|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - Calling func before main()
Hi,
I am looking for a way how to call a desired
function before main() is called in C mode ?
Something like
#pragma startup foo
in other compilers.
--
Karol Gottan
Feb 01 2004
Very simple... ;-)
static int result_of_foo = foo ();
int main ( int, char **, char ** )
{
return ( 0 );
}
static int foo ()
{
// Do something before 'main' is being invoked.
return ( 0 );
}
HTH
Karol Gottan wrote:
Feb 01 2004
<jan smartsoft.us> wrote :Very simple... ;-) Feb 01 2004
Karol Gottan wrote:<jan smartsoft.us> wrote :Very simple... ;-) Feb 02 2004
<scottm cs.ucla.edu> wrote : [...]You're not compiling C++ code, are you? Feb 02 2004
Jan Knepper wrote:Very simple... ;-) Feb 01 2004
<jan smartsoft.us> wrote :Jan Knepper wrote:Very simple... ;-) Feb 01 2004
Another way is to define a class at global level that has a constructor.
The constructor will be called before main().
Example:
struct foo {
foo() {cout << "do stuff before main\n";}
~foo() {cout << "do stuff after main\n";}
} myfoo;
int main()
{
cout << "here we are in main\n";
}
Feb 01 2004
Before someone takes the initiative and starts elaborating on this example, this question is a comp.lang.c++ FAQ item, whihc also covers how to sequence object allocation and construction before main() is called. Steve Strand <snstrand comcast.net> wrote: Feb 01 2004
<g> I was thinking that the question would come from a C++ classes book or something like that. It is one of the standard questions employers will ask you during a technical job interview for a C/C++ coding job... Scott Michel wrote:Before someone takes the initiative and starts elaborating on this example, this question is a comp.lang.c++ FAQ item, whihc also covers how to sequence object allocation and construction before main() is called. Steve Strand <snstrand comcast.net> wrote: Feb 01 2004
|