View Single Post
  #13   Spotlight this post!  
Unread 15-02-2004, 12:19
Mark McLeod's Avatar
Mark McLeod Mark McLeod is offline
Just Itinerant
AKA: Hey dad...Father...MARK
FRC #0358 (Robotic Eagles)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2002
Location: Hauppauge, Long Island, NY
Posts: 8,856
Mark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond reputeMark McLeod has a reputation beyond repute
Re: printf isn't printf-ing. Help!

Quote:
Originally Posted by Meandmyself
OK, so if Current.theta is an unsigned int, and I'm setting it equal to an unsigned long, what bits will I lose in the process? the most significant 8?
for example, what if I had this:
Code:
 
unsigned long longvar = 0xFAAABBBB;
unsigned int shortvar = 0;
shortvar = longvar;
shortvar would be 0xBBBB, right?

and a second question about that, am I getting an overflow error because the pic does math on an int level, and when an operation goes higher than an int I get an overflow error?

Thanks for all your help so far.
Yes, you'd get 0xBBBB.
Always use a type that will hold your largest possible final value.
In this case you could shift right 16 bits.

The PIC evaluates an expression based on the largest type variable used in the expression. You can add an explicit type, e.g., (long), to force the PIC to use a long for all calculations.

[edit] You can also force the C compiler to use at least (int) for all calculations rather than defaulting to the types of the variables used in the expression. In MPLAB under Project -> Build Options... -> MPLAB C18 tab add the compiler option -Oi+
__________________
"Rationality is our distinguishing characteristic - it's what sets us apart from the beasts." - Aristotle

Last edited by Mark McLeod : 16-02-2004 at 08:28.