Re: Adding custom code to the .init section of a library

fjh@cs.mu.OZ.AU (Fergus Henderson)
18 Nov 1999 02:42:17 -0500

          From comp.compilers

Related articles
Adding custom code to the .init section of a library priya@alpha.ece.ucsb.edu (Priya Narasimhan) (1999-11-16)
Re: Adding custom code to the .init section of a library fjh@cs.mu.OZ.AU (1999-11-18)
Re: Adding custom code to the .init section of a library mwh@gradin.cis.upenn.edu (1999-11-18)
Re: Adding custom code to the .init section of a library zandy@cs.wisc.edu (Victor Zandy) (1999-11-18)
Re: Adding custom code to the .init section of a library plakal@cs.wisc.edu (1999-11-18)
| List of all articles for this month |

From: fjh@cs.mu.OZ.AU (Fergus Henderson)
Newsgroups: comp.compilers
Date: 18 Nov 1999 02:42:17 -0500
Organization: Computer Science, The University of Melbourne
References: 99-11-082
Keywords: C, linker

Priya Narasimhan <priya@alpha.ece.ucsb.edu> writes:


>On a SPARC Solaris 2.x machine, I am able to add custom code
>to the .init section of a library using
>
>#pragma init (blah-blah)
>
>where blah-blah() is written in C code. How can I do this on
>an Intel machine running RedHatLinux 6.0 with gcc?
...
>[I suggested a C++ static constructor. -John]


Using a C++ static constructor is probably the most portable solution.
However it may be problematic if the initialization code uses third-party
header files that contain constructs such as unprototyped functions that
work only as C, not as C++. An alternative solution that works with GNU C
is to use `__attribute__((constructor))'. See the "Function Attributes"
section of the "C extensions" section of the gcc manual for details.


--
Fergus Henderson <fjh@cs.mu.oz.au>
WWW: <http://www.cs.mu.oz.au/~fjh>
PGP: finger fjh@128.250.37.3


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.