LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 15
HELP :- #pragma startup directive goes unrecognized


Hi

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
Pratyush

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
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,692

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
pratyush
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
Phoxis
Member
 
Registered: Feb 2008
Location: India, Kolkata
Distribution: Fedora 16
Posts: 59

Rep: Reputation: 16
Check out the
Code:
__attribute__((constructor))
__attribute__((destructor))
__attribute__((constructor (PRIORITY)))
__attribute__((destructor (PRIORITY)))

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

Code:
#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: http://phoxis.org/2011/04/27/c-langu...tors-with-gcc/
 
1 members found this post helpful.
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:20 AM.

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