Custom Constructor and Destructor in GCC

The GNU GCC compiler provides a specific attribute to define our own custom constructor and destructor for your C Program. Here is the sample code:

#include <stdio.h> void my_const(void) __attribute__ ((constructor)); void my_destr(void) __attribute__ ((destructor )); int main() { printf("n Inside Main n"); return 0; } void my_const(void) { printf("n Inside Constructor n"); } void my_destr(void) { printf("n Inside Destructor n"); }

Advertisements
Tagged with: ,
Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: