www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/30/20:59:47

Xref: news2.mv.net comp.os.msdos.djgpp:3278
From: elric AT wheel DOT ucdavis DOT edu (Jeffrey Taylor)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: How safe is this?
Date: 30 Apr 1996 00:33:03 GMT
Organization: Davis Community Network - Davis, California, USA
Lines: 27
Message-ID: <4m3n3v$dc7@mark.ucdavis.edu>
References: <4laoi6$cgk AT groa DOT uct DOT ac DOT za> <830625577 DOT 295snx AT techm DOT pl DOT my>
NNTP-Posting-Host: wheel.dcn.davis.ca.us
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019