Date: Sun, 12 Nov 2000 14:30:32 -0800 From: "Crist J . Clark" <cjclark@reflexnet.net> To: Salvo Bartolotta <bartequi@inwind.it> Cc: freebsd-questions@FreeBSD.ORG Subject: Re: OT: curious (??) integer types behavio(u)r... Message-ID: <20001112143032.Q75251@149.211.6.64.reflexcom.com> In-Reply-To: <20001112.21033200@bartequi.ottodomain.org>; from bartequi@inwind.it on Sun, Nov 12, 2000 at 09:03:32PM %2B0000 References: <20001112.21033200@bartequi.ottodomain.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Nov 12, 2000 at 09:03:32PM +0000, Salvo Bartolotta wrote: > [ not sure whether/where to send this dumb remark ] > > Dear FreeBSD'ers, > > The following simple (test) program seems to behave anomalously on my > FreeBSD 4.2-BETA (sources as of this morning) PIII system. One odd warning, but everything works as expected. > <blockquote> > /* A simple test program */ > > #include <stdio.h> > > main() > { > char c1 = -128; > char c2 = 127; > unsigned char c = 255; > > short int si1 = -32768; > short int si2 = 32767; > unsigned short int si = 65535; > > int d1 = -2147483648; > int d2 = 2147483647; > unsigned int d = 4294967295; > unsigned long int l = 4294967295; /* redundant */ > > printf("%d %d %d %d %d %d %d %d %d %ld\n", c1, c2, c, si1, > si2, si, d1, d2, d, l); > } > > </blockquote> > > >====> cc -o mytest mytest.c > mytest.c: In function `main': > mytest.c:15: warning: decimal constant is so large that it is unsigned > mytest.c:17: warning: decimal constant is so large that it is unsigned > mytest.c:18: warning: decimal constant is so large that it is unsigned > > > >====> ./mytest > -128 127 255 -32768 32767 65535 -2147483648 2147483647 -1 -1 > (?) ^^^^^^ > > > > To sum up: > 1) cc complains about line 15, but the limit is correctly displayed by > the program (!); Yeah, that is strange. > 2) cc complains about lines 17 and 18; the limits are INcorrectly > displayed. > > I am probably missing something very trivial here. The warnings about 17 and 18 _are_ true. The constants are so large that they are unsigned. Now, you want them to be unsigned, but the compiler does not seem to have the ESP module up yet, so it warns you anyway. The last two numberrs are correctly displayed. Look at your printf(3). You asked the numbers to be displayed as signed decimals (%d), and that's how they are being shown. I think you want to see, printf("%d %d %d %d %d %d %d %d %u %lu\n", c1, c2, c, si1, si2, si, d1, d2, d, l); ^ ^ Which will print what you seem to be expecting. So, one warning seems suspect, the others are correct, but the program actually behaves as expected. -- Crist J. Clark cjclark@alum.mit.edu To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001112143032.Q75251>