
20-01-2007, 01:53
|
 |
Registered User
AKA: Matt
 FRC #3302 (Turbo Trojans)
Team Role: Programmer
|
|
Join Date: Jan 2006
Rookie Year: 2005
Location: Clawson, Michigan
Posts: 34
|
|
|
Re: I hate "C"
Quote:
Originally Posted by Mike Betts
I've been working with embedded processors for over 25 years (and vacuum tubes, et cetera for 10 years before that). I think that I first learned about C and stack variables in college (circa 1978).
dcbrown's explanation is correct. When viewed from a pure "software" perspective, the fact that this processor passes parameters on the stack is, perhaps, confusing. C allows a variable argument list and it is up to the called function (in this case, printf) to parse the format string (the first parameter of the function is actually a pointer to a string) and determine how many variables there are and how large each one is. Your first %d in your format string indicated a 2 byte variable was the second parameter on the stack. When you put a long variable in the calling statement, 4 bytes were pushed onto the stack. That meant that all of your subsequent parameters were 2 bytes off...
I would refer you to K&R for more details. It was the bible back in the 70's and, in my opinion, it is still the bible.
For specifics on C as implemented for this processor, I'd look here.
Regards,
Mike
|
Hmm, very interesting.
Last time I'll make a printf mistake...once tried to concatenate strings in a prtinf...printf("measurement: "+measurement);..have to start remembering what language I'm in 
|