![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Padding with zeros. | sbasetty | Shell Programming and Scripting | 10 | 05-18-2009 07:09 PM |
| Padding in Unix | rudoraj | Shell Programming and Scripting | 3 | 02-21-2008 12:06 AM |
| AWK and padding values | kshelluser | UNIX for Dummies Questions & Answers | 3 | 11-29-2006 05:14 PM |
| Padding | vijaygopalsk | UNIX for Dummies Questions & Answers | 2 | 06-27-2003 10:51 AM |
| Padding issues | informshilpa | UNIX for Advanced & Expert Users | 2 | 03-01-2002 01:51 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Padding is implementation dependent. Basically it means the the objects inside the struct have their beginning addresses moved (padded with bytes) so the start of each object can be accessed by the hardware efficiently.
Misalignment of objects can result in a SIGBUS core dump, or very much slower access to the object. Some compilers have a pragma to turn off or alter padding. Others provide warnings about padding. |
|
||||
|
for gcc try to define your structure like this:
struct gtpp_hdr6 { unsigned char flag; // 1 byte unsigned char message_type; // 1 byte unsigned short length; // 2 bytes unsigned short sequence; // 2 bytes } __attribute__((__packed__)); and check again. This attribute shows compiler that this structure used for data packets and compiler will not do padding |
|
||||
|
Its actually low level issue. Padding stores all the data element started from even addresses. In this mechanism char also take 2 bytes ( one Byte stored in current even address, next data element can store in next even address, in b/w odd address is wasted). But it improves data reading efficiency.
|
|
||||
|
A program that shows padding issues and offsets
Hi,
When working in many client/server situations that data being passed is passed in data structures. It's important to know the padding arrangements between two architects, so here is an example program that shows how to see the offsets. #include <stdio.h> int main (void) { struct { char a; int i; double d; } st; printf ("st size: %d\noffset a: %d\noffset i: %d\noffset d:%d\n", sizeof (st), ((char *) (&st.a)) - ((char *)&st), ((char *) (&st.i)) - ((char *)&st), ((char *) (&st.d)) - ((char *)&st)); } |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|