| Jeff Abrahamson on 6 Dec 2003 11:51:02 -0500 |
|
What am I doing wrong here?
/* int.c */
#include <stdio.h>
int
main(int argc,
char *argv[])
{
signed long SL;
unsigned long UL, UL2;
SL = -1;
UL = (unsigned long)SL;
printf("SL=%ld, UL=%ld\n", SL, UL);
UL2 = ~0;
printf("SL=%ld, UL=%ld\n", SL, UL);
return 0;
}
Compiling and running,
jeff@asterix:int-cast $ gcc -Wall int.c -o int && ./int
SL=-1, UL=-1
SL=-1, UL=-1
jeff@asterix:int-cast $
I would expect at least the second line to show UL equal to a very
large integer, certainly something non-negative.
--
Jeff
Jeff Abrahamson <http://www.purple.com/jeff/>
GPG fingerprint: 1A1A BA95 D082 A558 A276 63C6 16BF 8C4C 0D1D AE4B
Attachment:
pgpp7dMm26OBJ.pgp
|
|