public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* init code
@ 2008-06-11 17:39 dreese
  2008-06-11 17:50 ` David Daney
  0 siblings, 1 reply; 2+ messages in thread
From: dreese @ 2008-06-11 17:39 UTC (permalink / raw)
  To: gcc-help


Does gcc currently posses the functionality to do the following?

I would like to have gcc compile in a function that initializes a global variable into the target programs memory space. I need this initialization function to be called before any code is executed from the target program. I need to have gcc do this for every program that it compiles with out being asked. 

Does anyone have any ideas?

Thanks for your time.
Dale Reese

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: init code
  2008-06-11 17:39 init code dreese
@ 2008-06-11 17:50 ` David Daney
  0 siblings, 0 replies; 2+ messages in thread
From: David Daney @ 2008-06-11 17:50 UTC (permalink / raw)
  To: dreese; +Cc: gcc-help

dreese@vandals.uidaho.edu wrote:
> Does gcc currently posses the functionality to do the following?
> 
> I would like to have gcc compile in a function that initializes a global variable into the target programs memory space. I need this initialization function to be called before any code is executed from the target program. I need to have gcc do this for every program that it compiles with out being asked. 
> 
> Does anyone have any ideas?
> 

Look at: __attribute__((constructor))

http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Function-Attributes.html

You would have to force the object containing the constructor to be linked to any program where this behavior is desired.

David Daney

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-06-11 17:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-06-11 17:39 init code dreese
2008-06-11 17:50 ` David Daney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).