Re: Simple fun g++ code..

Marek Habersack (grendel@vip.maestro.com.pl)
Sun, 22 Mar 1998 01:12:16 +0100 (CET)


On Thu, 19 Mar 1998, Vincent Cojot (Gosseyn SandPath) wrote:

> class programme {
> public:
> programme(void) {
> cout << "Hello world." << endl;
> exit(0);
> }
> ~programme(void) {
> cout << "Bye world." << endl;
> }
> };
> programme main;
The C/C++ linkers expect the program to start from the symbol named
"main" (mangled or not, with underscore or not - depends on the convention,
the unmangled name must be "main"). Note that I didn't say a "function", but a
symbol. You can name an array "main" and put machine code inside - your
program will work. In this case the compiler creates a global object whose
name is "main" - that satisfies the linker. The object, being a global one, is
created BEFORE the startup code calls main. The programme(void) constructor is
invoked and displays the "Hello world" string - then exits the program using
the exit() function which has the effect that the startup code which is
supposed to call "main" AFTER all the global objects are created, never runs -
the exit function starts the shutdown sequence which, among others, consists
of destroying all the global objects, and thus calling their destructors.
That's when the "Bye world" string gets displayed.

l8r, marek

----
"Hello John, have you seen The Standard four hours ago?
They fished a chick out of the Old Father...
Blond hair, blue eyes... She said she would be an actress or something...
Nobody knows what she was planning for, where she was going...
Funny thing she had smile on her face, she was smiling..."
"What a waste!"
-- Fish "Chelsea Monday"

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu