# A simple question again

• 07-09-2002
Kelvin
A simple question again
what is 0xFFFFFFFF ?
I am learning from sample source code.
here is a part of the code :

dwFileSize = GetFileSize(hFile, NULL);
if(dwFileSize != 0xFFFFFFFF)
{ ....
• 07-09-2002
Monster
It's the same as -1, assuming dwFileSize is a (signed) double word.

The binary notation for 0xFFFFFFFF is: 1111 1111 1111 1111 1111 1111 1111 1111

The most significant bit (left-most bit) holds the sign; 1 for negative, 0 for positive.

You calculate the value of a negative number by inverting it and adding 1.

1111 1111 1111 1111 1111 1111 1111 1111

Inverting:
0000 0000 0000 0000 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0001 = 1

So the value 0xFFFFFFFF is the same as -1
• 07-09-2002
marsface
and,

with dwError = GetLastError() you can obtain what went wrong.
• 07-09-2002
novacain
It means the function failed.

0xFFFFFFFF is #define'd as

INVALID_HANDLE
INVALID_FILE_SIZE
TIME_ZONE_ID_INVALID
TLS_OUT_OF_INDEXES

ect

in winbase.h
not to mention

INFINITE
NMPWAIT_WAIT_FOREVER
• 07-09-2002
Kelvin
Quote:

Originally posted by Monster

The binary notation for 0xFFFFFFFF is: 1111 1111 1111 1111 1111 1111 1111 1111

then the binary notation for FFFFFFFF is also 1111 1111 1111 1111 1111 1111 1111 1111

then what's the difference between them?
• 07-09-2002
Monster
Quote:

Originally posted by Kelvin

then the binary notation for FFFFFFFF is also 1111 1111 1111 1111 1111 1111 1111 1111

then what's the difference between them?

You need to put the 0x before it to tell the compiler it's a hexadecimal number:
Code:

```int i = 10; /* decimal 10 */ int j = 0x10; /* decimal 16 */ int k = FFFFFFFF; /* invalid */```
FFFFFFFF is not valid because the compiler thinks it's a decimal number, and F is not allowed in a decimal number.
• 07-09-2002
Kelvin
oic~
Thanks all ^^
• 07-09-2002
>>> if(dwFileSize != 0xFFFFFFFF)

That is actually poor style, you should use...

if(dwFileSize != INVALID_FILE_SIZE)

... the reason is that at some time, MS may decide to change the value of the return, but if they did so, they would also change the value of the named constant so your code would still work. I accept, of course, that it is unlikely in this case, however, using the raw value when a named constant has been specifically declared will cause you a problem one day.

You often find examples like this in MSDN - you'd have thought they for one would have known better.
• 07-09-2002
Kelvin
Quote:

>>> if(dwFileSize != 0xFFFFFFFF)

That is actually poor style, you should use...

if(dwFileSize != INVALID_FILE_SIZE)

... the reason is that at some time, MS may decide to change the value of the return, but if they did so, they would also change the value of the named constant so your code would still work. I accept, of course, that it is unlikely in this case, however, using the raw value when a named constant has been specifically declared will cause you a problem one day.

You often find examples like this in MSDN - you'd have thought they for one would have known better.

Thanks
but where can I find error constant like "INVALID_FILE_SIZE"?
• 07-09-2002
Traveller
Code:

```#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1) #define INVALID_FILE_SIZE ((DWORD)0xFFFFFFFF) #define INVALID_SET_FILE_POINTER ((DWORD)-1) #define INVALID_FILE_ATTRIBUTES ((DWORD)-1)```
Check out your header files, these are near the top of Winbase.h
• 07-09-2002
Kelvin
Thanks !
• 07-20-2002
Unregistered
Quote: