execution before main
Joseph Hadzima <[email protected]> Sat, 31 Dec 2005 08:44:32 -0800 (PST)
| Newsgroups | gmane.comp.programming.cppug |
|---|---|
| Message-ID | <[email protected]> |
HI
Yes C++ programs are easy, but if you're stuck with good
old C, ...
Did you try the -v switch when you compile and LINK
something simple like HelloWorld.c? My compiler attempts
to link with "__start" This is the first function to run,
it accepts all the command line arguments and then passes
them to
int main(int argc, char * argv[] )
So this is the function that always executes before main().
I'm not sure exactly how you would modify it, but checking
your compiler documentation may help. I also believe you
can set your linker command line to link to something else
prior to calling __start.
Please keep us posted how this works!
happy coding.
--- sumit kumar <[email protected]> wrote:
> At 05:54 2005-12-27, Jitendra Kumar wrote:
> >Hi all to the members of wonderful forum,
> >
> >Y'day i had an interview, this was the qstn:
> >
> >Write a program which will execute before the main
> >function, dont use #pragma or compiler level programs?
>
> what language? If C++, trivial: write a struct
> or class with your program in the constructor.
> define an instance as a global variable.
>
> in C? I have no idea.
>
>
> >Pls post the answer.
> >Thanku,
> >
> >Jitendra
> Maneesh Anand Samria <[email protected]> wrote:
> Lets try this
> #include<stdio.h>
> int before()
> {
> printf("HELLO");
> return 1;
> }
> int i = before();
> void main()
> {
> printf("main");
> }
>
> This wont work since initialiser must be a constant.
>
> Regards,
> Sumit kumar
>
HADZ.
The reasonable man adapts himself to the world;
the unreasonable one persists in trying to adapt
the world to himself. Therefore all progress depends
on the unreasonable man.
--George Bernard Shaw, Man and Superman (1903)
"Maxims for Revolutionists" Irish dramatist & socialist (1856 - 1950)
(this email sent using 100% recycled electrons)
------------------------ Yahoo! Groups Sponsor --------------------~-->
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/EbFolB/TM
--------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/cppug/
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/