View Single Post
  #1   Spotlight this post!  
Unread 22-03-2004, 14:02
gnormhurst's Avatar
gnormhurst gnormhurst is offline
Norm Hurst
AKA: gnorm
#0381 (The Tornadoes)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Trenton, NJ
Posts: 138
gnormhurst will become famous soon enoughgnormhurst will become famous soon enough
What the...? casting bug?

'splain this, somebody:

Code:
#define STRAIGHT_DRIVE_DIRECTION ( 127 + 30 )
 
      static int steeringValue = 0;
      . . .
      steeringValue = (int) ((STRAIGHT_DRIVE_DIRECTION));
      printf( "nav: DTC  %3d ", steeringValue  );
That printed a value of -99! Why?

Changing the assignment to:
Code:
      steeringValue = (int) ((unsigned char) (STRAIGHT_DRIVE_DIRECTION));
made it print "157" as expected the first time.

Is this weird, or is there something about type casting I don't understand?
__________________
Trenton Tornadoes 381
2004 Philadelphia Regional Winners
2006 Xerox Creativity Award
---
My corner of the USPTO.
My favorite error message from gcc: main is usually a function
My favorite error message from Windows: There is not enough disk space available to delete this file.