Re: Simple fun g++ code..

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


On Sat, 21 Mar 1998, Lin Zhe Min wrote:

> With exit(0) :
> Hello World!
>
> Without exit(0) :
> Hello World!
> Segmentation fault.
>
> So the "Bye World!" is not displayed. Well, this is a bit confusing,
> because with or without a exit(0), the destructor should always be
> excuted theoretically. (However, once exit() is called, the process is
> terminated by System.)
Not at all. THe SIGSEGV signal terminates the program immediately. How can you
imagine a program running when it is in an unknown state?

> There is something notable:
> 1. When using 'programme main;', g++ generates statically a constructor
> of class main, which does only call programme(), and a destructor,
> which does only call ~programme(). It is not efficient, but it is
> theoretically perfect.
> 2. Even though the entry point "main:" does nothing, the linker always
> know to execute the constructor of 'class main' first, while I haven't
> found any instructor in the assembly codes. I think it's tricky. :Q
The linker doesn't execute anything. It merely collects all the global
constructor addresses and puts them in a special data section which is then
iterated by the startup code which calls the constructors in the ordred given.
Same goes for the desctructors.

---
"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