Hello All,
Does anybody know how to make the settings for the BYTE ALIGNMENT /PACKING
for the structures.
If yes, what are the settings for it.??
The problem we are facing is
typedef struct
{
unsigned char VAR1[3];
}A;
typedef struct
{
A a; // 3- BYTE SIZE
unsigned int VAR2:8; // 1- BYTE SIZE
unsigned int VAR3:16; // 2- BYTE SIZE
}B;
The sizeof (A) comes out to be 3
and sizeof(B) comes out to be 7 (instead of 6).
This is because the VC compiler stuffs a byte after the first structure A.
Is there any settings for the alignment etc. to solve this .
Thanks
Rakesh Shrivastava
DCM Tech
New Delhi
Lookup the pragma directive "#pragma pack " in the SDK
f u cn rd ths u cn gt a gd jb n cmptr pgmg
-----Original Message-----
From: Rakesh Shrivastava
Sent: Saturday, April 29, 2000 2:51 PM
To: NT Developers Interest List
Subject: [ntdev] Byte Alignment
Hello All,
Does anybody know how to make the settings for the BYTE ALIGNMENT /PACKING
for the structures.
If yes, what are the settings for it.??
The problem we are facing is
typedef struct
{
unsigned char VAR1[3];
}A;
typedef struct
{
A a; // 3- BYTE SIZE
unsigned int VAR2:8; // 1- BYTE SIZE
unsigned int VAR3:16; // 2- BYTE SIZE
}B;
The sizeof (A) comes out to be 3
and sizeof(B) comes out to be 7 (instead of 6).
This is because the VC compiler stuffs a byte after the first structure A.
Is there any settings for the alignment etc. to solve this .
Thanks
Rakesh Shrivastava
DCM Tech
New Delhi
You are currently subscribed to ntdev as: xxxxx@dcmds.co.in
To unsubscribe send a blank email to $subst(‘Email.Unsub’)
From the VC docs:
pack
#pragma pack( [n] )
Specifies packing alignment for structure and union members. Whereas the
packing alignment of structures and unions is set for an entire translation
unit by the /Zp option, the packing alignment is set at the data-declaration
level by the pack pragma. The pragma takes effect at the first structure or
union declaration after the pragma is seen; the pragma has no effect on
definitions.
When you use #pragma pack(n), where n is 1, 2, 4, 8, or 16, each structure
member after the first is stored on the smaller member type or n-byte
boundaries. If you use #pragma pack without an argument, structure members
are packed to the value specified by /Zp. The default /Zp packing size is
/Zp8.
Jim
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@dcmds.co.in
Sent: Saturday, April 29, 2000 2:21 AM
To: NT Developers Interest List
Subject: [ntdev] Byte Alignment
Hello All,
Does anybody know how to make the settings for the BYTE ALIGNMENT /PACKING
for the structures.
If yes, what are the settings for it.??
The problem we are facing is
typedef struct
{
unsigned char VAR1[3];
}A;
typedef struct
{
A a; // 3- BYTE SIZE
unsigned int VAR2:8; // 1- BYTE SIZE
unsigned int VAR3:16; // 2- BYTE SIZE
}B;
The sizeof (A) comes out to be 3
and sizeof(B) comes out to be 7 (instead of 6).
This is because the VC compiler stuffs a byte after the first structure A.
Is there any settings for the alignment etc. to solve this .
Thanks
Rakesh Shrivastava
DCM Tech
New Delhi
You are currently subscribed to ntdev as: xxxxx@youngendeavors.com
To unsubscribe send a blank email to $subst(‘Email.Unsub’)
Or you can use compiler independent method:
#include “pshpackX.h” where X is required alignment (e.g. 1, 2, 4,
…)
#include “poppack.h”
These include files come with Platform SDK and for example NTIFS.H uses
them.
-----P?vodn? zpr?va-----
Od: xxxxx@dcmds.co.in [SMTP:xxxxx@dcmds.co.in]
Odesl?no: 29. dubna 2000 11:51
Komu: NT Developers Interest List
P?edm?t: [ntdev] RE: Byte Alignment
Lookup the pragma directive "#pragma pack " in the SDK
f u cn rd ths u cn gt a gd jb n cmptr pgmg
-----Original Message-----
From: Rakesh Shrivastava
Sent: Saturday, April 29, 2000 2:51 PM
To: NT Developers Interest List
Subject: [ntdev] Byte Alignment
Hello All,
Does anybody know how to make the settings for the BYTE ALIGNMENT /PACKING
for the structures.
If yes, what are the settings for it.??
The problem we are facing is
typedef struct
{
unsigned char VAR1[3];
}A;
typedef struct
{
A a; // 3- BYTE SIZE
unsigned int VAR2:8; // 1- BYTE SIZE
unsigned int VAR3:16; // 2- BYTE SIZE
}B;
The sizeof (A) comes out to be 3
and sizeof(B) comes out to be 7 (instead of 6).
This is because the VC compiler stuffs a byte after the first structure A.
Is there any settings for the alignment etc. to solve this .
Thanks
Rakesh Shrivastava
DCM Tech
New Delhi
You are currently subscribed to ntdev as: xxxxx@dcmds.co.in
To unsubscribe send a blank email to $subst(‘Email.Unsub’)
You are currently subscribed to ntdev as: xxxxx@sodatsw.cz
To unsubscribe send a blank email to $subst(‘Email.Unsub’)
Try:
#pragma pack(1)
typedef struct
{
unsigned char VAR1[3];
}A;
#pragma pack()
Mark
xxxxx@dcmds.co.in wrote:
Hello All,
Does anybody know how to make the settings for the BYTE ALIGNMENT /PACKING
for the structures.
If yes, what are the settings for it.??
The problem we are facing is
typedef struct
{
unsigned char VAR1[3];
}A;
typedef struct
{
A a; // 3- BYTE SIZE
unsigned int VAR2:8; // 1- BYTE SIZE
unsigned int VAR3:16; // 2- BYTE SIZE
}B;
The sizeof (A) comes out to be 3
and sizeof(B) comes out to be 7 (instead of 6).
This is because the VC compiler stuffs a byte after the first structure A.
Is there any settings for the alignment etc. to solve this .
Thanks
Rakesh Shrivastava
DCM Tech
New Delhi
You are currently subscribed to ntdev as: xxxxx@arx.com
To unsubscribe send a blank email to $subst(‘Email.Unsub’)
The long answer is this:
#pragma pack( push, , )
and to undo it/return to default:
#pragma pack( pop, )
Look up #pragma pack in the docs and it will explain the optional parameters
shown above.
Greg
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of xxxxx@dcmds.co.in
Sent: Saturday, April 29, 2000 4:21 AM
To: NT Developers Interest List
Subject: [ntdev] Byte Alignment
Hello All,
Does anybody know how to make the settings for the BYTE ALIGNMENT /PACKING
for the structures.
If yes, what are the settings for it.??
The problem we are facing is
typedef struct
{
unsigned char VAR1[3];
}A;
typedef struct
{
A a; // 3- BYTE SIZE
unsigned int VAR2:8; // 1- BYTE SIZE
unsigned int VAR3:16; // 2- BYTE SIZE
}B;
The sizeof (A) comes out to be 3
and sizeof(B) comes out to be 7 (instead of 6).
This is because the VC compiler stuffs a byte after the first structure A.
Is there any settings for the alignment etc. to solve this .
Thanks
Rakesh Shrivastava
DCM Tech
New Delhi
—
You are currently subscribed to ntdev as: xxxxx@pdq.net
To unsubscribe send a blank email to $subst(‘Email.Unsub’)
> Does anybody know how to make the settings for the BYTE ALIGNMENT /PACKING
for the structures.
#pragma pack(1)
- (in the source, surely) turns off alignment.
#pragma pack()
- turns it back on.
Max