There isn’t a packing issue here unless you change the type of the
structure members because the members as defined by the WDK/DDK are all
UINT8’s. If you do change the types, then you may be introducing
unpackable gaps because there is no way to pack a UINT32 into the space
filled by a UINT8 (if only there were). Adding #pragma pack to this
issue is at best a nop.
Warning 4214 is specifically that you’re using a non-standard
extension. Don’s suggesting was just to turn off the warning that the
MS header is using a non-standard extension. It’s a silly warning for a
MS header which is why in all the new headers the warning is turned off
inside the new versions of the file.
I believe this structure containing UINT’s would work while being
standard C and keeping bitfields which are easier to read than the
normal bit manipulations on bytes you normally see with SCSI.
typedef struct _MODE_DATA_COMPRESSION_PAGE {
UINT PageCode : 6;
UINT Reserved1 : 2;
UINT PageLength : 8;
UINT Reserved2 : 6;
UINT DCC : 1;
UINT DCE : 1;
UINT Reserved3 : 5;
UINT RED : 2;
UINT DDE : 1;
UCHAR CompressionAlgorithm[4];
UCHAR DecompressionAlgorithm[4];
UCHAR Reserved4[4];
} MODE_DATA_COMPRESSION_PAGE, *PMODE_DATA_COMPRESSION_PAGE;
On 8/28/2014 4:54 PM, Marion Bond wrote:
Also be aware that the structure packing can also have an effect on
the final binary layout. There is more on this in MSDN. Look at
pragma packSent from Surface Pro
*From:* Jeff Glass mailto:xxxxx
> Sent: ‎Thursday‎, ‎August‎ ‎28‎, ‎2014 ‎2‎:‎26‎ ‎PM
> To: Windows System Software Devs Interest List
> mailto:xxxxx
>
> Additionally, if the UCHAR bitfield didn’t pack differently than the
> UINT bitfield, the structure in the MS header wouldn’t be SCSI compliant.
>
> On 8/28/2014 10:41 AM, Tim Roberts wrote:
> > Jeff Glass wrote:
> >> While changing the UCHAR’s to UINTs eliminates the compiler warning.
> >> This is a SCSI structure (from a MS WDK header). It needs to be packed
> >> properly. Don’s suggestion is the way to go.
> > The Microsoft headers that include this already have the pragma to
> > disable 4214.
> >
> > However, changing from UCHAR to UINT for the bitfields will not change
> > the packing in any way. Some people have developed a rule in their
> > brains that the type of a bitfield should be the smallest type that fits
> > the field size. That’s a false rule. The C and C++ standards have both
> > always mandated that the type of a bitfield should be either “int” or
> > “unsigned int” (and Microsoft’s compiler happens to have an extension
> > that allows " int64" and "unsigned int64" for fields larger than 32
> > bits).
> >
> > There is no advantage to using “unsigned char” or “unsigned short” over
> > “unsigned int” in a bitfield, and using “unsigned int” makes you
> > standard-compliant.
> >
>
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev
>
> OSR is HIRING!! See http://www.osr.com/careers
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer</mailto:xxxxx></mailto:xxxxx>