473,549 Members | 2,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3169
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
1922
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 in a box and click a button at this point the daily packing packing number will be genrated. the packing guy will write it on the box.
29
8807
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; unsigned long large: 24; First question - is that the best way to declare the "large" one to ensure it's 3 bytes? Another suggestion I got was...
4
17676
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 b;
18
2027
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. Yet, in my understanding, attributes are only __gc and __value class specific and do not apply to __nogc classes. Is this correct ? If so, how is...
9
5854
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 as few packing peanuts as possible (to some reasonable approximation) to fill the gaps. I have found some c code and plenty of discussions on the...
18
7544
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 because I'm trying to refactor working code that is concise: 08 12 34 56 80 00
1
1614
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. error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagTEXTMETRICA): (0x02000029)Any idea if I...
0
1448
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. (My real data is not byte variables.) I wish to be able to populate a field in the message header and then
7
7007
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 case basis"? \\\ For example, suppose sometimes I receive the value '\x03hi' + \x04bye' for the struct:
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7715
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5087
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3480
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1057
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.