Tuesday, September 28, 2010

How to call a function before main and after main

1. Using GCC compiler on Linux/Solaris

/*main.c :this program tells how we can call a function before main() call and after main() call*/

#include

void my_ctor (void) __attribute__ ((constructor));
void my_dtor (void) __attribute__ ((destructor));

void
my_ctor (void)
{
printf ("hello before main()\n");
}

void
my_dtor (void)
{
printf ("bye after main()\n");
}

int
main (void)
{
printf ("hello\n");
return 0;
}

$gcc main.c
$./a.out
hello before main()
hello
bye after main()


2. Using CC compiler on Solaris[Using Pragma]

Using pragma
============


#pragma init (foo)

void foo()
{
printf("\nInside foo");
}

#pragma fini (bar)

void bar()
{
printf("\nInside bar");
}

int
main()
{
printf("\nInside main");
return 0;
}

$cc main.c
$./a.out
Inside foo
Inside main
Inside bar

43 comments:

Anonymous said...

Just desire to say your article is as astonishing.

The clarity in your post is simply spectacular and i
could assume you're an expert on this subject. Fine with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please continue the rewarding work.

Here is my web site; california golf schools

Anonymous said...

I have been exploring for a little for any high quality articles or weblog posts on this sort of space .
Exploring in Yahoo I eventually stumbled upon this site.
Reading this info So i am satisfied to express that I've an incredibly just right uncanny feeling I discovered exactly what I needed. I so much no doubt will make certain to do not omit this website and give it a glance on a relentless basis.

Review my site :: Sushi Orlando

Anonymous said...

Hi my friend! I want to say that this article is
amazing, nice written and include approximately all important infos.

I'd like to look more posts like this .

Feel free to surf to my web site japanese restaurant in moorestown nj

Anonymous said...

Thanks for the marvelous posting! I really enjoyed
reading it, you might be a great author. I will make certain to bookmark your blog and will
often come back later in life. I want to encourage you to
continue your great posts, have a nice holiday weekend!



My blog post :: florist supplies miami fl

Anonymous said...

My coder is trying to persuade me to move to .net from PHP.
I have always disliked the idea because of the expenses. But he's tryiong none the less. I've been using WordPress
on numerous websites for about a year and am worried about switching to
another platform. I have heard excellent things about
blogengine.net. Is there a way I can import all my wordpress posts into it?
Any help would be greatly appreciated!

Check out my page; http://www.boardcentralalert.sidcorporation.com

Anonymous said...

Piece of writing writing is also a fun, if you be acquainted with afterward you can write if not it
is complicated to write.

My page: Seafood Restaurant
my site :: Cheers Kissimmee

Anonymous said...

I was wondering if you ever considered changing the page layout of your site?

Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so
people could connect with it better. Youve got an awful lot
of text for only having 1 or 2 images. Maybe you could space it out better?


my weblog: physical therapist salary in florida

Anonymous said...

Hello there! This is kind of off topic but I need some guidance from an established blog.
Is it tough to set up your own blog? I'm not very techincal but I can figure things out pretty fast. I'm thinking about setting up
my own but I'm not sure where to start. Do you have any ideas or suggestions? Many thanks

Check out my web blog ... las vegas golf schools butch harmon

Anonymous said...

Appreciate the recommendation. Will try it out.

my web-site :: easy-golf-tips.com

Anonymous said...

Have you ever thought about adding a little bit more than just your articles?
I mean, what you say is fundamental and everything.
Nevertheless imagine if you added some great images or video clips
to give your posts more, "pop"! Your content is excellent but with pics and videos, this website could certainly be one of the
best in its field. Superb blog!

Feel free to visit my blog post :: dirrebreather.com

Anonymous said...

Sweet blog! I found it while browsing on
Yahoo News. Do you have any tips on how to get listed in Yahoo
News? I've been trying for a while but I never seem to get there! Thank you

Stop by my blog: womens fitness swim suits

Anonymous said...

I know this if off topic but I'm looking into starting my own blog and was wondering what all is required to get set up? I'm assuming having a blog like yours would cost a pretty penny?
I'm not very web smart so I'm not 100% sure. Any tips or advice would be greatly appreciated. Cheers

my web page ... foursquare.com

Anonymous said...

My spouse and I absolutely love your blog and find most of your post's to be just what I'm looking
for. Would you offer guest writers to write content in your
case? I wouldn't mind writing a post or elaborating on most of the subjects you write related to here. Again, awesome web log!

Here is my website: studio 9 shoes
my web page: http://www.openbottles.com

Anonymous said...

Neat blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple tweeks would really make my blog jump out.
Please let me know where you got your theme. With
thanks

Here is my webpage ... digital to analog converter

Anonymous said...

I'm starting up a online website directory and was wondering if I can submit your blog? I'm trying
to grow my directory gradually by hand so that it retains quality.
I'll make sure and put your website in the best category and I'll also use,
"Blogger: My Stuff" as your anchor text. Be sure to let me know if this is ok with you by contacting me at: emilyashley@gmx.
de. Thanks

my blog post www.photographers.ie

Anonymous said...

Wow! This blog looks just like my old one!
It's on a entirely different subject but it has pretty much the same layout and design. Wonderful choice of colors!

My webpage :: ballroom dance shoes boys

Anonymous said...

Howdy just wanted to give you a quick heads up. The words
in your post seem to be running off the screen in Safari.
I'm not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I'd post to let you know.
The design look great though! Hope you get the issue resolved soon.

Cheers

Check out my web-site ... Jazz dance Shoes las vegas

Anonymous said...

Exploring digg.com I noticed your website bookmarked as:
Blogger: My Stuff. I am assuming you book marked it yourself and wanted to ask
if social book-marking gets you a good deal of visitors?
I've been contemplating doing some bookmarking for a few of my sites but wasn't certain if it
would generate any positive results. Thank you so much.

my web blog; dance shoes for salsa uk

Anonymous said...

I enjoy what you guys tend to be up too. This type
of clever work and reporting! Keep up the very
good works guys I've added you guys to blogroll.

my web page rs232 to usb converter circuit diagram

Anonymous said...

Write more, thats all I have to say. Literally, it seems as though you
relied on the video to make your point. You clearly know what youre talking about, why
throw away your intelligence on just posting videos
to your site when you could be giving us something informative to read?


Take a look at my site: device driver for hp officejet 4500 desktop

Anonymous said...

I'm really inspired with your writing abilities as neatly as with the format in your weblog. Is that this a paid subject matter or did you modify it your self? Anyway stay up the nice high quality writing, it's uncommon to peer a great weblog like this
one today..

Also visit my web-site ... foofara.com

Anonymous said...

Thanks in favor of sharing such a pleasant opinion, paragraph is good,
thats why i have read it completely

Here is my blog post; golf buggy batteries perth

Anonymous said...

This is a topic that's close to my heart... Best wishes! Where are your contact details though?

My web site; http://sunrisesinthewest.org

Anonymous said...

Wow, this post is fastidious, my sister is analyzing these things,
so I am going to inform her.

My blog post - golfsmith austin used clubs

Anonymous said...

I'm curious which blogging platform you're using?

I'm new to operating a blog and have been thinking about using the Ning platform. Do you think this is a good foundation to start with? I would be extremely thankful if I could ask you some questions through email so I can learn a bit more prior to getting started. When you have some free time, please contact me at: krisisaacs@gmail.com. Kudos

Feel free to surf to my web site - short term lease apartments tampa fl

Anonymous said...

Have you ever thought about writing an e-book or guest authoring on other sites?
I have a blog centered on the same topics you discuss
and would really like to have you share some stories/information.

I know my subscribers would enjoy your work. If you are even remotely interested, feel
free to send me an e-mail.

Feel free to surf to my web site :: national corporate housing companies

Anonymous said...

Excellent post. Keep posting such kind of info
on your blog. Im really impressed by your blog.
Hello there, You've performed a great job. I'll certainly digg it and for my part
suggest to my friends. I'm sure they will be benefited from this site.

Also visit my web blog :: Commercial Led Lighting

Anonymous said...

I do not leave a response, but I browsed a few of the comments on this page "How to call a function before main and after main".
I do have some questions for you if it's okay. Is it only me or does it look like a few of these responses appear like they are left by brain dead visitors? :-P And, if you are writing at additional social sites, I'd
like to follow you. Could you list of the complete urls of your social pages like
your linkedin profile, Facebook page or twitter feed?

Here is my blog post ... Short game classes

Anonymous said...

Neat blog! Is your theme custom made or did you download it
from somewhere? A design like yours with a few simple tweeks would really make
my blog shine. Please let me know where you got your theme.
Kudos

Also visit my page ... furnished apartments pensacola beach fl

Anonymous said...

What a data of un-ambiguity and preserveness of valuable familiarity on
the topic of unexpected emotions.

Feel free to surf to my weblog ... applied kinesiology allergy testing

Anonymous said...

Hola! I've been reading your web site for some time now and finally got the bravery to go ahead and give you a shout out from New Caney Tx! Just wanted to say keep up the fantastic work!

Stop by my web blog :: Las Vegas Golf Schools

Anonymous said...

Hello! I just noticed your webpage: Blogger: My Stuff when
I was searching reddit.com. It looks as though someone enjoyed your blog so much
they decided to bookmark it. I'll definitely be coming back here more often.

Take a look at my website :: caig circuit board pen

Anonymous said...

I am really loving the theme/design of your blog.
Do you ever run into any internet browser compatibility problems?
A number of my blog visitors have complained about my website not operating correctly in Explorer
but looks great in Chrome. Do you have any solutions to help
fix this problem?

Feel free to surf to my homepage :: epoch golf tees

Anonymous said...

Hmm it seems like your site ate my first comment (it was extremely long) so I guess I'll just sum it up what I had written and say, I'm thoroughly enjoying your blog.
I too am an aspiring blog writer but I'm still new to the whole thing. Do you have any helpful hints for beginner blog writers? I'd genuinely
appreciate it.

Visit my blog :: middle back spasms symptoms at night

Anonymous said...

Hello, I do believe your site might be having internet browser compatibility issues.

When I take a look at your blog in Safari, it looks fine however,
if opening in Internet Explorer, it's got some overlapping issues. I just wanted to give you a quick heads up! Apart from that, great website!

Also visit my webpage - Orlando Sushi

Anonymous said...

I'm not sure why but this website is loading incredibly slow for me. Is anyone else having this problem or is it a problem on my end? I'll check back
later on and see if the problem still exists.

Review my homepage: golf lessons for beginners singapore

Anonymous said...

Hello my friend! I wish to say that this article is amazing, great written and include approximately all vital infos.

I would like to look more posts like this .

my web site: www.winterparkbusinesslist.com

Anonymous said...

I enjoy what you guys are up too. Such clever work and exposure!
Keep up the good works guys I've added you guys to our blogroll.

Feel free to visit my weblog :: mueller athletic tape

Anonymous said...

Hello to all, how is everything, I think every one is getting more
from this site, and your views are pleasant in favor of new people.


Also visit my page Chiropractor

Anonymous said...

This post gives clear idea for the new people of blogging, that
genuinely how to do blogging and site-building.


Also visit my site wholisticuniverse.com

Anonymous said...

An outstanding share! I have just forwarded this
onto a friend who had been conducting a little homework on
this. And he actually ordered me dinner due to the fact that I stumbled upon it for him.
.. lol. So allow me to reword this.... Thanks for the meal!
! But yeah, thanks for spending the time to talk about this matter here on your web
site.

Visit my homepage inversion table teeter

Anonymous said...

This paragraph will help the internet visitors for building up new blog or
even a blog from start to end.

Feel free to visit my site; chiropractor-orlando.com

Anonymous said...

At this time it sounds like BlogEngine is the top blogging platform out
there right now. (from what I've read) Is that what you're using on your blog?


my page - personal injury attorney