Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 11-10-2007, 02:56 PM   #1
LQ Newbie
Registered: Jul 2007
Posts: 24

Rep: Reputation: 15
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

Last edited by pratyush; 11-11-2007 at 12:16 AM. Reason: Needed to change the title
Old 11-10-2007, 03:22 PM   #2
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
As far as I know, gcc simply doesn't support the startup pragma.
Old 11-10-2007, 03:31 PM   #3
LQ Newbie
Registered: Jul 2007
Posts: 24

Original Poster
Rep: Reputation: 15
Then, does that mean that I have no way of calling any function before my main function gets called?
Old 04-22-2012, 03:07 AM   #4
Registered: Feb 2008
Location: India, Kolkata
Distribution: Fedora 16
Posts: 59

Rep: Reputation: 16
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:
1 members found this post helpful.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
#pragma vedanu Programming 2 02-21-2007 05:15 AM
#pragma pack directive rajesh_b Programming 2 09-25-2006 05:05 AM
Disable warnings with a pragma (g++) Kikazaru Programming 3 07-01-2006 10:58 PM
Linux equivalents for #pragma DavidW567 Programming 2 03-09-2005 02:24 PM
Pragma: no-cache workaround OhLordy Linux - Networking 1 05-09-2003 06:18 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:05 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration