473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Byte Packing

How does the byte packing and the byte alignment work in VC++ compiler? What is the effect of #pragma pack(n) on the alignment and byte packing
for example while using the structur
struc

double a
char b
char c
}
in a 8 byte packing the sizeof structure is 16. Could anyone explain.
Nov 17 '05 #1
1 3158
Gajendra wrote:
How does the byte packing and the byte alignment work in VC++
compiler? What is the effect of #pragma pack(n) on the alignment and
byte packing. for example while using the structure
struct
{
double a;
8 bytes.
char b;
1 byte
char c;
1 byte
6 bytes of padding to make the struct-size a multiple of 8. This is
necessary to ensure that in an array of structs that the 'a' member always
has 8-byte alignment.
};
in a 8 byte packing the sizeof structure is 16. Could anyone explain.


8+1+1+6=16

-cd
Nov 17 '05 #2

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

Similar topics

2
by: gbb0330 | last post by:
Hi all I need some advice. the daily packing number will be used to match a box with its label. the guys in the warehouse will get a list of items to pack. they will find the item - put it...
29
by: Ed Morton | last post by:
I have 2 counters - one is required to be a 2-byte variable while the other is required to be 3 bytes (not my choice, but I'm stuck with it!). I've declared them as: unsigned short small;...
4
by: Shashi | last post by:
Can somebody explain how the byte alignment for structures work, taking the following example and considering: byte of 1 Byte word of 2 Bytes dword of 4 Bytes typedef struct { byte a; word...
18
by: Edward Diener | last post by:
Is the packing alignment of __nogc classes stored as part of the assembly ? I think it must as the compiler, when referencing the assembly, could not know how the original data is packed otherwise....
9
by: fraz | last post by:
Does anyone have code to solve a 3-d bin packing problem in php? I am trying to solve the issue of packing various sized rectangular shaped objects into boxes of three different sizes so as to use...
18
by: p.lavarre | last post by:
Can Python not express the idea of a three-byte int? For instance, in the working example below, can we somehow collapse the three calls of struct.pack into one? 08 12 34 56 80 00 I ask...
1
by: Asfar | last post by:
Hi, I have created a mfc extension dll in VS2005. In code generation I set the Alignemnt to 1Byte and compile. This works fine. Now I add clr support to my dll and i get errors when linking....
0
by: shofu_au | last post by:
Hi Group, I am trying without much luck to pack messages into a byte buffer using get and set accessors. I have attached a simplified example of what I am trying to do using byte variables....
7
by: p.lavarre | last post by:
How do I vary the byte offset of a field of a ctypes.Structure? How do I "use the dynamic nature of Python, and (re-)define the data type after the required size is already known, on a case by...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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...

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.