Date: 07 Mar 2006 10:22:24 -0500 From: Lowell Gilbert <freebsd-questions-local@be-well.ilk.org> To: kamal kc <kamal_ckk@yahoo.com> Cc: freebsd-questions@freebsd.org Subject: Re: range of 32 bit unsigned int/long Message-ID: <44pskyi8jz.fsf@be-well.ilk.org> In-Reply-To: <20060306120257.61959.qmail@web30012.mail.mud.yahoo.com> References: <20060306120257.61959.qmail@web30012.mail.mud.yahoo.com>
next in thread | previous in thread | raw e-mail | index | archive | help
kamal kc <kamal_ckk@yahoo.com> writes: > the 16 bit unsigned integer takes the value as i checked myself > for 0 to 2^16-1 (=65535). > > but the 32 bit unsigned integer/long does not take the > value from 0 to 2^32-1 (4294967295). > instead 32 bit unsigned int/long takes the value from > 0 to 2^31-1 (2147483647). No, it takes on the full range you expected. [Depending on your hardware platform, of course.] Use UINT_MAX and see what values it takes. > the gcc shows that the message > warning: this decimal constant is unsigned only in ISO C90 > > what is happening, i am confused. It is telling you exactly what is happening. If you don't specify that a constant is unsigned, the latest version of the C Standard specifies that it is treated as int, long int, or long long int (the first one of that list which it will fit in). Take the following code as an example and look for a really good reference on the C language. #include <limits.h> int main(void) { unsigned int u = UINT_MAX; unsigned int m = 4294967295U; printf("UINT_MAX is %u\n",u); printf("m is %u\n",m); return 0; } You also might be interested in the comp.lang.c FAQ. http://www.eskimo.com/~scs/C-faq/faq.html
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44pskyi8jz.fsf>