The hexadecimal constant in c is unsigned, although I used the suffix L

I know this is a simple question, but I'm confused. I have a pretty typical gcc warning, which is usually easy to fix:
warning: comparison between signed and unsigned integer expressions

Whenever I have a hexadecimal constant with the most significant bit, like 0x80000000L, the compiler interprets it as unsigned. For example, compiling this code with -Wextra will raise a warning (gcc 4.4x, 4.5x):

int main()
{
long test = 1;
long *p = &test;
if(*p != 0x80000000L) printf("test");
}

I deliberately fixed a constant for so long, so why is this happening?

+5
source share
5 answers

The answer to this question is relevant:

Unsigned hexadecimal constant in C?

- L , :

long
unsigned long
long long
unsigned long long

. C99, [6.4.4.1].

long, , 32 , , () 0x80000000. , unsigned long, .

, long 64 , long.

+9

c .

+1

32- long ( 32- int), 0x80000000 32- , unsigned. , .

+1

. , , , , , . (unsigned long)0x80000000L

0

Hex C/++ . .

0

All Articles