Thread: I hate "C"
View Single Post
  #7   Spotlight this post!  
Unread 20-01-2007, 00:48
maniac_2040's Avatar
maniac_2040 maniac_2040 is offline
Registered User
AKA: Matt
FRC #3302 (Turbo Trojans)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: Clawson, Michigan
Posts: 34
maniac_2040 is infamous around these partsmaniac_2040 is infamous around these partsmaniac_2040 is infamous around these partsmaniac_2040 is infamous around these parts
Send a message via MSN to maniac_2040
Re: I hate "C"

Quote:
Originally Posted by Mike Betts View Post
Matt,

There is a lot of your declarations not shown (such as your pid structure) but I'm guessing your issue is with the printf statement. "measurement" is declared as a long at the top of your function and being passed to printf as a long but printf is expecting an int. It should be cast as "(int) measurement". This would throw off all of your stack variables by two bytes each.

Output may be non-zero but I doubt it is correct.

Good Luck...

Mike

ha....it sickens me that this was actually the problem. This was the THIRD time I have been screwed by those printf's in C(used to java, C++). Thank You. That fixed the problem, but I'm curious as to how this works. 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? Could you point me to a paper or something that explains how some of these "inner workings" work?

EDIT: I knew it expected ints and I forgot that I changed measurement to a long, but I still wouldn't have expected that one mistake to mess up the rest of the function.