Paul.L.Snyder on 6 Dec 2003 12:03:02 -0500 |
Try using %lu as your format, rather than %ld. %u is the conversion specifier for unsigned decimal. %d is a conversion specifier for signed decimal. Paul ------------------------------ Paul L. Snyder SCS Technology Office - Emerging Technology GlaxoSmithKline From: plug-admin Sent: 12/06/2003 11:41 AM To: PLUG <plug@lists.phillylinux.org> Subject: [PLUG] printf and unsigned long 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 ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|