Regarding Padding bytes

M

manochavishal

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
 
K

Keith Thompson

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.

See question 2.12 in the comp.lang.c FAQ said:
Even i have not understood the paragraph 4.
[snip]

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

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.
 
K

Keith Thompson

In standard i have come across:

6.2.6 Representations of types
6.2.6.1 General
[snip]

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

Even i have not understood the paragraph 4.
[snip]

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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,241
Latest member
Lisa1997

Latest Threads

Top