Ammendum: C correctly interprets -2147483648 as negative

by qbguy (no login)

Here is a nice transcript. I included my versions of Windows, gcc, and GNU cat.

C:\>ver

Microsoft Windows XP [Version 5.1.2600]

C:\>gcc --version
gcc (GCC) 3.4.5 (mingw special)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

C:\>cat --version
cat (GNU textutils) 2.0
Written by Torbjorn Granlund and Richard M. Stallman.

Copyright (C) 1999 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

C:\>cat > test.c
#include <stdio.h>

int main ()
{
printf("%d", -2147483648);
return 0;
}

^Z

C:\>gcc -ansi test.c -o test

C:\>test
-2147483648


As you can see from the transcript, C correctly interprets -2147483648 as a negative number. Therefore, since C does not have any weird voodoo that causes -2147483648 to be unsigned, the bug has to be in your compiler.


Posted on Apr 7, 2008, 3:39 PM
from IP address 76.195.133.68

Respond to this message   

Return to Index


Response TitleAuthor and Date
printf does what the format sting tells it to do:counting_pine on Apr 7
 With std::cout, it prints positiveqbguy on Apr 7
  gcc defaults to C89, and C++98 isn't any better regarding this aspect.rpgfan3233 on Apr 7