How does the standard C preprocessor interpret "0xFFFFFFFF"?

How does the standard C preprocessor interpret "0xFFFFFFFF": 4G-1 or -1?

The same question for "~ 0" ...

If the answer is -1, then how can I interpret it as 4G-1 (i.e. is there any other way besides using 4294967295 explicitly)?

PS: I tried this on MS Visual Studio (using a comparison, not a call to "printf", of course, since the latter just prints according to the specified "%"), and the answer was 4G-1. But I'm not sure that MS Visual Studio uses the standard C preprocessor.

thanks

+4
source share
4 answers

, 0xFFFFFFFF . ( #if #elif), ; 0xFFFFFFFF 2 32 -1 4294967295 ( C99 64 ).

, #if #elif, . :

  • int
  • unsigned int
  • long int
  • unsigned long int
  • long long int
  • unsigned long long int

:

  • int 32 , long 32 , long;
  • int 32 , long - 32 , unsigned long;
  • int - 32 , unsigned int;
  • int 32 , int.

unsigned int unsigned long.

0xFFFFFFFF 2 32 -1 4294967295; .

(, -1) ( ) 0xFFFFFFFF :

int n = 0xFFFFFFFF;

. int , 32 , 2 32 -1. int 32 , ; -1 - , .

~0, int, , 1, -1, .

?

+3

Per C 2011 (N1570) 6.10.1 4, , , (intmax_t uintmax_t). 0xFFFFFFFF 2 32 -1, C unsigned long. ~0 C.

#if #elif. , , . . #if #elif C, .

+2

ANSI C , cpp , , , . , :

#if 0xFFFFFFFF == -1
...
#else
...
#endif
+1

, .

 #define N  0xffffffff

- , N, #if. , C , , . ,

 long number = N;  // declare and initialize to symbolic value N

, , long , .

+1

All Articles