1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

storing structure(size less than 1 byte) to file

Discussion in 'C' started by sreejith, Nov 22, 2007.

  1. sreejith

    sreejith New Member

    Joined:
    Nov 22, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    Plz replay .............for storing a structure(containing a 4 bit length variable) to a file
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    As you have posted the query in the introduce yourself forum no one can even make a guess which programming language you are looking help in. Help us to help you.
     
  3. sreejith

    sreejith New Member

    Joined:
    Nov 22, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    thanks for your attention, C++ is the language which I forget to mention, can I store the structure (<1 byte) without using type casting. ................hoping your replay
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Moved to C-C++ forum.
     
  5. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    You can't have a struct containing less than 1 byte in C or C++.

    I'm guessing you declared a bit-field
    Code:
    struct foo {
      unsigned int bits : 4;
    };
    
    This will ALWAYS be padded to some multiple of the size of a char.

    Show us some more of what it is you're trying to do.
     

Share This Page