View Single Post
  #5   Spotlight this post!  
Unread 22-08-2004, 15:21
Tom Saxton's Avatar
Tom Saxton Tom Saxton is offline
Registered User
no team (Issaquah Robotics Society)
Team Role: Mentor
 
Join Date: Dec 2003
Rookie Year: 2003
Location: Sammamish, WA
Posts: 98
Tom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud ofTom Saxton has much to be proud of
Re: Weird Stuff in ifi_startup.c

Quote:
Originally Posted by ScottWolchok
Mmkay, so I look at this and I'm really lost. First of all, what does the underscore at the start of all these functions signify? Second, isn't assembler in C done like a function call? Thirdly, is that entry function even necessary? And last, I thought C programs started with the main function, but this code calls it instead... @_@
Although I like to avoid broad generalizations, I believe *every* C program begins with code that runs before "main". There's a bunch of stuff that has to happen before "main" gets called. For example, globals variables have to be initialized (either with explicit values, or with zeros if none are specified) which may involve copying values from ROM (or an executable file) to RAM. Things are even more complex if running under a full OS, where the addresses of functions in external libraries have to be found and written into the program's RAM image or in-memory tables.

Doing this work is very dependent on the architecture, so special code has to be written for each platform (Macintosh, Linux, Windows, Edu RC, etc), generally in assembly. This is done by some combination of the OS folks and the compiler support programmers since some is specific to the OS and some is specific to the language being used.

Thankfully, C programmers generally don't need to know anything about that preamble code except in very unusual circumstances.
__________________
Tom Saxton
http://www.idleloop.com/