0xff padding?

This is a discussion on 0xff padding? within the C Programming forums, part of the General Programming Boards category; i have this code Code: int next_byte(char **filebuf, int *psize) { if (*psize) { (*psize)--; return *(*filebuf)++; } return END_BUF; ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    552

    0xff padding?

    i have this code
    Code:
    int next_byte(char **filebuf, int *psize)
    {
      if (*psize) {
        (*psize)--;
        return *(*filebuf)++;    
      }
      return END_BUF;
    }
    The next byte in filebuf is, say, 0xd8, but next_byte will return 0xffffffd8. Is there any particular reason why its not returning 0x000000d8
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    Does this do the same thing for any hex value above 0x80?

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    casting the return statement didnt work, but chaning the param to unsigned char did. Thanks.
    Last edited by *ClownPimp*; 01-23-2003 at 12:08 PM.
    C Code. C Code Run. Run Code Run... Please!

    "Love is like a blackhole, you fall into it... then you get ripped apart"

  4. #4
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    > yep

    If that was to me, then read Salem's explanation - that's why; sign extension.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange struct padding?
    By cyberfish in forum C++ Programming
    Replies: 8
    Last Post: 07-12-2011, 10:42 PM
  2. To generate bar code from a number
    By darkducke in forum C Programming
    Replies: 18
    Last Post: 01-16-2008, 06:33 AM
  3. string padding and replacement functions
    By George2 in forum Tech Board
    Replies: 4
    Last Post: 11-19-2006, 01:40 AM
  4. Prob with padding in BMP image files
    By tin in forum Game Programming
    Replies: 2
    Last Post: 01-09-2006, 08:23 AM
  5. Structure Padding, pragma pack...
    By P.Phant in forum C Programming
    Replies: 4
    Last Post: 06-04-2003, 06:56 AM

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