From owner-freebsd-questions Sun Nov 12 14:30:38 2000 Delivered-To: freebsd-questions@freebsd.org Received: from mailhost01.reflexnet.net (mailhost01.reflexnet.net [64.6.192.82]) by hub.freebsd.org (Postfix) with ESMTP id 7C0E437B479 for ; Sun, 12 Nov 2000 14:30:35 -0800 (PST) Received: from 149.211.6.64.reflexcom.com ([64.6.211.149]) by mailhost01.reflexnet.net with Microsoft SMTPSVC(5.5.1877.197.19); Sun, 12 Nov 2000 14:29:08 -0800 Received: (from cjc@localhost) by 149.211.6.64.reflexcom.com (8.11.0/8.11.0) id eACMUWf21419; Sun, 12 Nov 2000 14:30:32 -0800 (PST) (envelope-from cjc) Date: Sun, 12 Nov 2000 14:30:32 -0800 From: "Crist J . Clark" To: Salvo Bartolotta Cc: freebsd-questions@FreeBSD.ORG Subject: Re: OT: curious (??) integer types behavio(u)r... Message-ID: <20001112143032.Q75251@149.211.6.64.reflexcom.com> Reply-To: cjclark@alum.mit.edu References: <20001112.21033200@bartequi.ottodomain.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <20001112.21033200@bartequi.ottodomain.org>; from bartequi@inwind.it on Sun, Nov 12, 2000 at 09:03:32PM +0000 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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. >
> /* A simple test program */ > > #include > > 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); > } > >
> > >====> 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