Regarding Padding bytes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • manochavishal@gmail.com

    Regarding Padding bytes

    Hi,

    In standard i have come across:

    6.2.6 Representations of types
    6.2.6.1 General

    6.When a value is stored in an object of structure or union type,
    including in a member
    object, the bytes of the object representation that correspond to any
    padding bytes take
    unspecified values.42) The value of a structure or union object is
    never a trap
    representation, even though the value of a member of the structure or
    union object may be
    a trap representation.

    I have not understood what padding bytes are and why they are used in
    representation.

    Even i have not understood the paragraph 4.

    4.Values stored in non-bit-field objects of any other object type
    consist of n × CHAR_BIT
    bits, where n is the size of an object of that type, in bytes. The
    value may be copied into
    an object of type unsigned char [n] (e.g., by memcpy); the resulting
    set of bytes is
    called the object representation of the value. Values stored in
    bit-fields consist of m bits,
    where m is the size specified for the bit-field. The object
    representation is the set of m
    bits the bit-field comprises in the addressable storage unit holding
    it. Tw o values (other
    than NaNs) with the same object representation compare equal, but
    values that compare
    equal may have different object representations .

    what is difference between a bit-field and a non-bit-field object.

    *Values stored in bit-fields consist of m bits,
    where m is the size specified for the bit-field.*

    This i couldn't understand.

    Anyone please help me in understanding this.

    Thanks in advance

  • Keith Thompson

    #2
    Re: Regarding Padding bytes

    "manochavishal@ gmail.com" <manochavishal@ gmail.com> writes:[color=blue]
    > In standard i have come across:
    >
    > 6.2.6 Representations of types 6.2.6.1 General
    >
    > 6.When a value is stored in an object of structure or union type,
    > including in a member object, the bytes of the object representation
    > that correspond to any padding bytes take unspecified values.42) The
    > value of a structure or union object is never a trap representation,
    > even though the value of a member of the structure or union object may
    > be a trap representation.
    >
    > I have not understood what padding bytes are and why they are used in
    > representation.[/color]

    See question 2.12 in the comp.lang.c FAQ, <http://www.c-faq.com/>.
    [color=blue]
    > Even i have not understood the paragraph 4.
    >[/color]
    [snip][color=blue]
    >
    > what is difference between a bit-field and a non-bit-field object.[/color]

    A bit field is a member of a structure whose declaration specifies its
    size in bits. For example:

    struct foo {
    unsigned int bit0:1
    unsigned int bit1:1
    unsigned int bit2:1
    unsigned int bit3:1
    unsigned int nibble1:4;
    unsigned int nibble2:4;
    unsigned int nibble3:4;
    };

    See also question 2.26 in the comp.lang.c FAQ.

    --
    Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.

    Comment

    • Keith Thompson

      #3
      Re: Regarding Padding bytes

      "manochavishal@ gmail.com" <manochavishal@ gmail.com> writes:[color=blue]
      > In standard i have come across:
      >
      > 6.2.6 Representations of types
      > 6.2.6.1 General
      >[/color]
      [snip][color=blue]
      >
      > I have not understood what padding bytes are and why they are used in
      > representation.
      >
      > Even i have not understood the paragraph 4.
      >[/color]
      [snip][color=blue]
      >
      > what is difference between a bit-field and a non-bit-field object.
      >
      > *Values stored in bit-fields consist of m bits,
      > where m is the size specified for the bit-field.*
      >
      > This i couldn't understand.[/color]

      If you're having trouble with things like this, you should be studying
      a book or other tutorial rather than trying to learn the language from
      the standard. The standard is designed to precisely define the
      language for implementers and programmers, not to teach it.

      Kernighan & Ritchie's _The C Programming Language_, 2nd Edition, is
      one of the best books, especially if you have some previous
      programming experience. There are some other good books and tutorials
      out there -- and a *lot* of really bad ones.

      --
      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
      San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
      We must do something. This is something. Therefore, we must do this.

      Comment

      Working...