Original Post
🔒 Locked
Buffer overflow[SOLVED]
Advertisement
Quote:
Original post by Ectara
With a simple statement such as:
unsigned char foo = 0xFF;
foo later evaluates to -1, throwing off my calculations. Can anyone explain why?
EDIT: I forgot to change %d to %u. Ignore said post.
You know, in C++ you could use operator>> overloads for I/O and avoid these kinds of problems automatically. Seeing as how you apparently care enough about type safety to bother with unsigned-type variables in the first place, you ought to use a type-safe I/O scheme as well. :)
Quote:
Original post by SiCrane
1) operator<<, not operator>>
2) operator<< on a char type will output the char as a character not as an integer.
For some reason I must have been assuming the problem was with reading the value rather than displaying it, but then it wouldn't have behaved as described. :/
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement