Solved

What is the Compiler Doing?

Posted on 2000-02-25
2
195 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add elements to existing standard structure 2 95
Add values of each row in an array 3 50
Create a path if not exists 7 68
object oriented programming comparison 5 52
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

929 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now