Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

When I open up the some of the often used header files like vector.h or cstdlib.h it just seems like a mess of #ifndefine #define #endif statements.

Can anyone decode that mess and give me a glimpse into whats going on in there?

share|improve this question

closed as too broad by gnat, MichaelT, GlenH7, Bart van Ingen Schenau, Wayne M Aug 1 at 18:42

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

    
vector.h and cstdlib.h are standard header files for C and C++ respectively, there's nothing new to see there. –  Mahmoud Hossam Mar 24 '11 at 22:10
    
That's not even true, and of course there is something to see there. The standard does not tell if they must be actual files and the implementation might be (and is) different between compilers. –  Tamás Szelei Mar 24 '11 at 23:14
    
@Tamás the implementation will still be platform specific –  Mahmoud Hossam Mar 25 '11 at 0:07
    
Do you think the implementation in g++'s headers are the same on windows as the MSVC's? –  Tamás Szelei Mar 25 '11 at 10:51
1  
@Mahmoud Hossam: cstdlib.h is not standard C or C++. stdlib.h is standard C, and is explicitly included in the C++ standard, and therefore is standard C++. cstdlib is standard C++, although with slightly different semantics. cstdlib.h is a combination of the old C system header naming convention and the new C++ system for using the C standard library. –  David Thornley Mar 25 '11 at 17:25

2 Answers 2

up vote 6 down vote accepted

A lot of the #defines are to configure the same header for lots of different circumstances (ASCII or widechar or unicode) or platforms (32 or 64 bit) If you open them in visual studio it will color them so that the ones which are 'on' for your setup are more obvious.

But it is basically a bunch of preprocessor stuff!

edit: The actual source in MSVC is unreadable because it contains lots of platform details - it's not a good place to start trying to understand it. See is-there-a-readable-implementation-of-the-stl question

share|improve this answer
    
So where can I actually see the nitty gritty of how some of the STL containers work? –  Phyllostachys Mar 24 '11 at 23:04

That "mess" as you call it is there to guarantee that the correct code will be generated depending on your compilation options. Not so easy writing header files for use by millions of people under various platforms/conditions.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.