Mail Archives: djgpp/1996/04/30/20:59:47
Kenneth Foo (kenfoo AT techm DOT pl DOT my) wrote:
: In article <4laoi6$cgk AT groa DOT uct DOT ac DOT za> fnunez AT cs DOT uct DOT ac DOT za writes:
: >Last night I was fooling around and the idea struck me of making a function
: >run automatically before main() starts up. I thought about it for a while and
: >came up with this little gem:
: >/* autostart.cc */
: >extern "C" void start(void);
: >class __autorun__
: >{
: > public:
: > __autorun__(void) { start(); };
: >} __autorun__;
: >Compiling this sucker to a .o file and linking it with plain C programs
: >(for C++ programs change 'extern "C"' to just 'extern') will cause a function
: >called 'start' to run before main().
: >My question is - how save and/or portable is this?
One problem you can have is if you use anything that needs to be
initialized too. Examples are the predefined stream (cin, cout, cerr) or
files (stdin, stdout, stderr), and parts of the run-time library. The
order can and will vary without much rhyme or reason.
--
============================================
Without my guitar, I am a poet without arms.
- Michael Bloomfield
============================================
- Raw text -