Mail Archives: djgpp/2000/10/17/10:30:13.1
Derek Chew <sdchew AT email DOT com> wrote:
> most recently, I noticed that one of my old functions that I wrote using
> TC has been acting wierdly.. I did some further investigate a bit futher
> and found that this line of code executes differently in TC and GCC
Yes, and rightly so. The code behaves perfectly correctly, on both
architectures (assuming you #include <stdio.h> somewhere before that
main() function, as you should).
[...]
> on TC, I will get the desire result of 65535 as the 16-bit unsigned int
> will overflow into and display this value... but apparently, under
> DJGPP/GCC, an unsigned int is 32-bit and I get the unwanted value of
> 4294967295 ...
It's your idea of a 'desired' or 'wanted' result that is incorrect. To
cite an old computer lore:
Computers hardly ever do what you want them to --- they do exactly
what you *tell* them, instead.
You expressed your desire of getting 65535 as the printed value in a
way that C compilers don't generally understand. TC happened to do
what you wanted, but that was pure coincidence.
The broken assumption in your piece of code is that 'unsigned int'
would always be a 16bit datatype. In DJGPP, and many other C
compilers, that's not the case. The only guarantee granted by the
language is that unsigned int will always be at least an effective 16
bits long. But it can easily be more.
The standard header file <limits.h> is your friend. Read up about it
in your TC docs, or in a textbook on C.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -