Constructors in C

1 view
Skip to first unread message

Bhatnagar Achindra

unread,
May 27, 2005, 3:27:15 AM5/27/05
to giGA...@googlegroups.com
#include <unistd.h>
#include <stdio.h>
void __attribute__ ((constructor)) aa()
{
fprintf(stdout,"Hello Worldn");
}


/* print example code */
int main(int argc,char *argv[]) {
fprintf(stdout,"Control reached in main()n");
return 0;
}

Nishant Sonar

unread,
May 27, 2005, 9:41:43 AM5/27/05
to giGA...@googlegroups.com

 
Tricker One.....


whers the object created? how can we access it?

Nishant Sonar
20, Tirupati Apartments,
Shivtirth Nagar,Paud Road
Kothrud, Pune(M.S.)
Mob:9823871676
Tel:020-25398002

Bhatnagar Achindra

unread,
May 27, 2005, 11:36:36 AM5/27/05
to giGA...@googlegroups.com
These are Libraries exported initialization and cleanup routines -
using the gcc

__attribute__((constructor)) and
__attribute__((destructor))

function attributes. Constructor routines are executed before dlopen
returns (or before main() is started if the library is loaded at load
time). Destructor routines are executed before dlclose returns (or
after exit() or completion of main() if the library is loaded at load
time). The C prototypes for these functions are:

void __attribute__ ((constructor)) my_init(void);
void __attribute__ ((destructor)) my_fini(void);

These two special functions, _init and _fini, can be used to control
constructors and destructors. However, they are obsolete, and their use
can lead to unpredicatable results. Libraries should not use these; use
the function attributes constructor and destructor above instead.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages