Solved

What is the Compiler Doing?

Posted on 2000-02-25
2
200 Views
Last Modified: 2010-08-05
I am using VC++ 6.0.  What happens when a file such as #include<iostream> is inserted into several different files all within the same project?  Obviously, it is not necessary to include a file more than once but it seems to be done quite often.   Does this hinder the performance of the executable?  What exactly is happening?  Just wondering...
0
Comment
Question by:guile1
2 Comments
 
LVL 1

Accepted Solution

by:
Binder earned 100 total points
ID: 2559000
  No, it don´t hinder the performance of the executable, just
the performance of the compiler (a little bit). But there is a way
to minimize this effect. Looking at the start of iostream.h we found:

#ifndef _INC_IOSTREAM
#define _INC_IOSTREAM

....
#endif

   and of course several other lines of code. This means that
if the file wasn´t already included (if the symbol  _INC_IOSTREAM
wasn't defined yet) then the compiler includes it. If the symbol
was already defined, the compiler didn´t include it again.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2559096
The use of #ifdef in that maner is very common.  It is necessary because C/C++ has rules against multiple definitions of the same "thing" in the same translation unit.  Without those #ifdef guards, the code would probably not compile.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question