-   Programming (
-   -   #pragma startup directive goes unrecognized (

pratyush 11-10-2007 02:56 PM

HELP :- #pragma startup directive goes unrecognized

I am using Red Hat 11 Linux as my operating system.

I have written a simple program in C. I want to call a function before the main function gets called. For doing the same, I am using

#pragma startup.

My code is as follows:

#include <stdio.h>

void func();

#pragma startup func 0

int main()
printf("\nInside main\n");
return 0;

void func()
printf("\nInside func()\n");

But when I try to compile the code, the compiler is not able to recognize the pragma startup directive.
> gcc -Wall testPragma.c

testPragma.c:5: warning: ignoring #pragma startup func

Could anyone please help me in compiling the code so that I can use the pragma startup directive in my code?

Thanks and regards

Mara 11-10-2007 03:22 PM

As far as I know, gcc simply doesn't support the startup pragma.

pratyush 11-10-2007 03:31 PM

Then, does that mean that I have no way of calling any function before my main function gets called?

Phoxis 04-22-2012 03:07 AM

Check out the

__attribute__((constructor (PRIORITY)))
__attribute__((destructor (PRIORITY)))

constructs in gcc. To execute a function prior to main you need to do:


#include <stdio.h>

void begin (void) __attribute__((constructor));
void end (void) __attribute__((destructor));

int main (void)
  printf ("\nInside main ()");

void begin (void)
  printf ("\nIn begin ()");

void end (void)
  printf ("\nIn end ()\n");

Have a look here:

All times are GMT -5. The time now is 03:43 AM.