delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/04/12/05:16:54

Date: Sun, 12 Apr 1998 12:16:29 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Conrad Wei-Li Song <conradsong AT mail DOT utexas DOT edu>
cc: djgpp AT delorie DOT com
Subject: Re: startup functions on gnu c/c++?
In-Reply-To: <199804120455.XAA18360@waller.net>
Message-ID: <Pine.SUN.3.91.980412121256.3322W-100000@is>
MIME-Version: 1.0

On Sat, 11 Apr 1998, Conrad Wei-Li Song wrote:

> How to I define functions to be called on program startup before main is
> called?

Declare these functions with the ``constructor'' attribute, like this:

  static void __attribure__((constructor)) my_startup (void)
  {
   ....
  }

Note that these functions are called in the order they are seen by the 
linker when it links the program.  (This is only important if you have 
several such functions which depend on each other.)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019