Re: [algogeeks] Call a function before main() in C

2010-06-30 Thread jalaj jaiswal
pragma startup and exit works in turbo c On Wed, Jun 30, 2010 at 3:50 PM, Mohd Yasir wrote: > here is the code. > > void init(void) __attribute__ ((constructor)); > void init(void) { > // your code goes here > } > > Muhammad Yasir > University Of karachi > > > On Wed, Jun 30, 2010 at 12:52 PM, a

Re: [algogeeks] Call a function before main() in C

2010-06-30 Thread Mohd Yasir
@Sachin Sharma you didn't try it i think.try this using gcc. #include void init(void) __attribute__ ((constructor)); void init(void) { printf("\nthis is init function"); } int main () { printf("\nthis is main function"); } On Wed, Jun 30, 2010 at 2:50 PM, sachin sharma wrote: > THIS CODE

Re: [algogeeks] Call a function before main() in C

2010-06-30 Thread Terence
gcc use __attribute__ instead of #pragma #include #ifndef __GNUC__ void beforemain(); void aftermain(); #pragma startup beforemain #pragma exit aftermain #else void beforemain() __attribute__((constructor)); void aftermain()__attribute__((destructor)); #endif int main() { printf("\ni

Re: [algogeeks] Call a function before main() in C

2010-06-30 Thread Yavor Nikolov
I don't think there is a STANDARD way to do that in plain C. Probably non-standard approaches to accomplish that is possible; why would you need that anyway? Regards, Yavor On Wed, Jun 30, 2010 at 13:20, Mohd Yasir wrote: > here is the code. > > void init(void) __attribute__ ((constructor)); >

Re: [algogeeks] Call a function before main() in C

2010-06-30 Thread sachin sharma
THIS CODE IS GIVES EXPECTED OUTPUT ON TURBO ONLY On Wed, Jun 30, 2010 at 1:22 PM, anand verma wrote: > i tried this c code on gcc compiler... > > this code doesn't give expected output. > > OUTPUT: i m inside main > > y? > > > > -- > You received this message because you are sub

Re: [algogeeks] Call a function before main() in C

2010-06-30 Thread Mohd Yasir
here is the code. void init(void) __attribute__ ((constructor)); void init(void) { // your code goes here } Muhammad Yasir University Of karachi On Wed, Jun 30, 2010 at 12:52 PM, anand verma wrote: > i tried this c code on gcc compiler... > > this code doesn't give expected output. > > OUT

Re: [algogeeks] Call a function before main() in C

2010-06-30 Thread anand verma
i tried this c code on gcc compiler... this code doesn't give expected output. OUTPUT: i m inside main y? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe

Re: [algogeeks] Call a function before main() in C

2010-06-29 Thread Sandeep .A.S.
Hi, I tried in Linux m/c. looks like the gcc will not support the startup and exit pragma if we execute the gcc -Wall filename.c we will get the below mentioned warning Warning : ignoring #pragma startup functionname Regards, Sandeep On Wed, Jun 30, 2010 at 1:30 AM, Varma wrote: > Hi All, >

Re: [algogeeks] Call a function before main() in C

2010-06-29 Thread sachin sharma
yes u can do in c using the pragma Directive there are two directive that allowes u to runyour function before the call to main or termination of the main 1) #pragma startup 2) #pragma exit implementation: void beforemain(); void aftermain(); #pragma startup beforemain #pragma startup aft

[algogeeks] Call a function before main() in C

2010-06-29 Thread Varma
Hi All, Is there any way to call our function before main() is called ? I know there is a way in C++ as below , but Is there a standard way in C ? #include class CStatic { public: CStatic() { cout << "Before Main!" << endl; } ~CStatic() { cout << "After Main!" << endl; } }; CStatic cs