functions in includeed files in C++

Started by
7 comments, last by Scet 18 years, 10 months ago
When you include a file in C++ such as iostream, it contains the function definitions. Where are the functions?
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
Advertisement
In the source (.c .cc .cpp) files. Like your code should be too ;)
____________________________________________________________Programmers Resource Central
Quote:Original post by Tera_Dragon
In the source (.c .cc .cpp) files. Like your code should be too ;)


He's asking where the stream functions are, not his own functions.

I believe they are in the .lib(or .a) files that you link with or a DLL. Most compilers will link with the standard libraries without you having to say so.
Quote:Original post by Scet
Quote:Original post by Tera_Dragon
In the source (.c .cc .cpp) files. Like your code should be too ;)


He's asking where the stream functions are, not his own functions.

I believe they are in the .lib(or .a) files that you link with or a DLL. Most compilers will link with the standard libraries without you having to say so.


Ah ok, missed that. Sorry about that, Scet is right.
____________________________________________________________Programmers Resource Central
are the .lib/.a files code files and included with #include as well?
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
Nope, .lib (or .a) is used by the linker to create the executable by "copying" in the functions and symbols it needs. DLLs (or .so) are linked when the application is run (thus the name Dynamic Runtime Library).

IIRC the standard library source ships with VisualStudio.

Cheers,
Drag0n
-----------------------------"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook"...nobody ever accused English pronounciation and spelling of being logical." -- Bjarne Stroustrup"...the war on terror is going badly because, if you where to compare it to WWII, it's like America being attacked by Japan, and responding by invading Brazil." -- Michalson
thanks
How does the linker know to include these files?
and is there code in these files?
"Are you threatening me, Master Jedi?" - Chancellor Palpatine
Quote:Original post by chaosgame
How does the linker know to include these files?


Any file you include, header or not, becomes part of the file you included it into, just as if you had cut and pasted it.

Quote:and is there code in these files?


Yes. Mostly class definitions with inline functions.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Normally you would have to add them to project options however any modern compiler automatically includes the standard library .lib files(for things like iostream).

They don't contain C++ code. Instead they contain precompiled code(machine code/debug symbols) that the linker adds to your executable(.exe) to form the program.

Basically the function definitions are in the plain text headers so the compiler can see mistakes before linking and the libraries contain the actual machine code(or something close to it).

This topic is closed to new replies.

Advertisement