473,506 Members | 17,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Mar 16 '06 #1
2 3215
"ma***********@gmail.com" <ma***********@gmail.com> writes:
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, <http://www.c-faq.com/>.
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.

--
Keith Thompson (The_Other_Keith) ks***@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.
Mar 16 '06 #2
"ma***********@gmail.com" <ma***********@gmail.com> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@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.
Mar 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
6144
by: s.seitz | last post by:
hi gods and programmers! i've got a weird problem with strlen() in C. in a current project, i need to AES_decrypt() some string. By now, i'm using the libssl (openssl) API. To get this...
28
20694
by: ramu | last post by:
Hi all, I understand that some compilers pad some bytes to the aggregate data types in order to access the members of the aggregate data types(i.e. structure) fast. This depends on the...
20
2287
by: Lalatendu Das | last post by:
hi let's say i have a structure struct test { int A; char B; int C; }; this above structure defination always going to take 16 byte in memeory in whatever manner we align the member variables...
2
1619
by: John Smith | last post by:
Hi, I have a question regarding the initialisation of aggregates: The C (99) standard states: section 6.7.8, paragraph 21 states: If there are fewer initializers in a brace-enclosed list than...
5
4018
by: Hallvard B Furuseth | last post by:
Does struct assignment copy padding bytes? Some compilers do, but I couldn't find anything in the standard which says they must. What I need is for any padding bytes to contan initialized values...
14
1986
by: Francine.Neary | last post by:
Consider the following situation. I have a large static array s of structs, say of size 500. I also need a smaller array of chars, say of size 100, which has nothing to do with the struct. To...
24
2084
by: karthikbalaguru | last post by:
Hi, I find that the structure padding is not being taken into account while using 'new' operator. Is there a way to enable it ? struct Dataunit { char dataid; int keyid;
12
4766
by: Kislay | last post by:
case 1 : struct s { char c1; // 8 double d; // 8 int i1; // 4 char c2; // 4 int i2; // 4 };
3
3513
by: vikas talwar | last post by:
Hi All, Can you please explain me how the 'C' compiler allocate memory to 'struct'. Please go thu the example below and pls suggest me the solution for my problem. Here is my structure...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.