Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

What is the Compiler Doing?

Posted on 2000-02-25
2
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 1

Accepted Solution

by:
Binder earned 400 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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.

664 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