星期三 十二月 03, 2008

/* On Solaris Platform */
#pragma init (fct[,fct])
#pragma fini (fct[,fct])

/* On Linux Platform */
void __attribute__ ((__constructor__)) fct (void){...}
void __attribute__ ((__destructor__))  fct (void){...} 

As I tested, Gcc 4.4.x on Ubuntu only supports the later form. While on Solaris, either SunStudio or Gcc (only 3.4.3 is available currently) supports both of them.

While there is a little different between SunStudio and Gcc, in case we declared two functions (let's say f1, f2) with attribute __constructor__, the call sequence would be f1 then f2 with SunStudio, but f2 then f1 with Gcc. However, the call sequence for 'destructors' is just the same -- f1 then f2.

This blog copyright 2009 by yongsun