order of how c++ program

Hi, i was just wondering, what is the first file which is read when you launch an executable program, obviously it is the .cpp file (i think), but what if you have two .cpp files, will it be the one with the winmain()/main() function?
I mean, how does the compiler handle more than one .cpp
When you run an executable there are no .cpp files around anymore. They have been compiled into object code and linked.

Theoretically, compilation units (each .cpp plus all its #includes) could be compiled in any order, since they're all independent from each other. I don't know what actually happens, though.
so when i have 2 .cpp files, when they are compiled they are actually one complete one, and the first function to be used/run is the winmain() one (if its a windows application)?
It doesn't matter which is compiled first, when a compiler is done with one file it forgets everything it just converted and moves onto the next file, with no knowledge of what previous cpp files contained
The compiler takes .cpp files plus the included headers as input and outputs an object code file (.obj) for each .cpp file. That is called a compilation unit. Once the compiler is done, the linker takes all those compilation units and ties them together. That is why a compilation unit can use a function just by knowing its prototype. It's the linker's job to link each of them to its definition.

And yes, main() marks the entry point of the application. IIRC, in Windows programs there's a hidden main() which sets some stuff up and calls WinMain().
Thanks
Topic archived. No new replies allowed.