stdint.h
Corinna Vinschen
vinschen@redhat.com
Tue Sep 20 16:39:00 GMT 2005
On Sep 20 18:19, Corinna Vinschen wrote:
> On Sep 20 17:22, Ralf Corsepius wrote:
> > On Tue, 2005-09-20 at 12:23 +0200, Corinna Vinschen wrote:
> > > When uncommenting every other problem in the file, there's also a bug
> > > in evaluating the INT32*_MIN values:
> > >
> > > INT32_MIN, INTLEAST32_MIN are printed as the positive value
> > > 2147483648, not -2147483648.
> > Check your preprocessed sources:
> > ...
> > long long arr3[] = {
> > INT8_MIN,
> > INT16_MIN,
> > INT32_MIN,
> > INT64_MIN,
> > ...
> >
> > Preprocessed:
> > long long arr3[] = {
> > -128,
> > -32768,
> > -2147483648,
> > -9223372036854775808,
> >
> > Also: cat printint.c
> > #include <stdio.h>
> > #include <stdint.h>
> > #include <inttypes.h>
> >
> > int main()
> > {
> > printf( "%" PRId32 "\n", INT32_MIN);
> > }
> >
> > Preprocessed:
> > ...
> > printf( "%" "d" "\n", -2147483648);
> > ...
> >
> > ./printint
> > -2147483648
> >
> > I'd say you've hit a bug in your GCC ;)
>
> ?!? Surprise, surprise. Thanks for pointing out this problem. Maybe
> a bug in printf? I'll have a look.
There's really something going on in gcc, but I'm not sure if that's
a bug or something to be expected within the specs.
The Cygwin definition of INT32_MIN is "(-2147483647 - 1)"
The RTEMS definition of INT32_MIN is "-2147483648".
The following expression
long long arr[] = {
INT32_MIN
};
is translated into the assembler code:
_arr:
.quad -2147483648
when using the Cygwin definition and into
_arr:
.quad 0x80000000
when using the RTEMS definition.
I'd like to point out that the glibc version of stdint.h also uses the
(-2147483647 - 1) variation. There must be a good reason, but I fail
to find a reference right now, which could help to explain this to all
of us. To state just the obvious, in the RTEMS case, the numerical part
of the constant, without the leading sign, is a constant which is by one
bigger than happens to fit into a 32 bit int.
Corinna
--
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat, Inc.
More information about the Newlib
mailing list