Thread: I hate "C"
View Single Post
  #13   Spotlight this post!  
Unread 20-01-2007, 01:30
Unsung FIRST Hero
Mike Betts Mike Betts is offline
Electrical Engineer
no team
Team Role: Engineer
 
Join Date: Dec 2001
Rookie Year: 1995
Location: Homosassa, FL
Posts: 1,442
Mike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond reputeMike Betts has a reputation beyond repute
Re: I hate "C"

Quote:
Originally Posted by maniac_2040 View Post
...Why does it throw off the stack variables by two bytes each?(Not that I know much about the "stack" anyways ) and how did you know this?
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
__________________
Mike Betts

Alumnus, Team 3518, Panthrobots, 2011
Alumnus, Team 177, Bobcat Robotics, 1995 - 2010
LRI, Connecticut Regional, 2007-2010
LRI, WPI Regional, 2009 - 2010
RI, South Florida Regional, 2012 - 2013

As easy as 355/113...