A simple question again

This is a discussion on A simple question again within the Windows Programming forums, part of the Platform Specific Boards category; what is 0xFFFFFFFF ? I am learning from sample source code. here is a part of the code : dwFileSize ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    85

    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)
    { ....

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    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

    Adding 1:
    0000 0000 0000 0000 0000 0000 0000 0001 = 1

    So the value 0xFFFFFFFF is the same as -1

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    47
    and,

    with dwError = GetLastError() you can obtain what went wrong.

    Regards,
    Robert

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    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
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    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?

  6. #6
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    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.

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    oic~
    Thanks all ^^
    Thanks your enthusiastic help

  8. #8
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> 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.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  9. #9
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    Originally posted by adrianxw
    >>> 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"?

  10. #10
    Registered User
    Join Date
    May 2002
    Posts
    317
    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

  11. #11
    Registered User
    Join Date
    Jul 2002
    Posts
    85
    Thanks !

  12. #12
    Unregistered
    Guest
    Originally posted by adrianxw
    >>> 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.
    MSY2K

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21