Re: [ntdev] Visual Studio 2013 WDK8.1 - bitfields

IMHO this is better practice

#pragma warning(push)

#pragma warning(disable :4214) // some comment as to why this was a good idea

#pragma warning(pop)

Sent from Surface Pro

From: Don Burn
Sent: ‎Thursday‎, ‎August‎ ‎28‎, ‎2014 ‎12‎:‎40‎ ‎PM
To: Windows System Software Devs Interest List

Use #pragma warning(disable:4214) … #pragma warning(default:4214) around
the whole structure.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@compuserve.com
Sent: Thursday, August 28, 2014 12:34 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Visual Studio 2013 WDK8.1 - bitfields

I’m trying to compile my SCSI tape drivers for 32-bit and 64-bit using
Visual Studio 2013 and WDK 8.1 (don’t laugh). I notice that there are no
tape driver samples in the WDK - or have I missed something?

This doesn’t compile:

typedef struct _MODE_DATA_COMPRESSION_PAGE {
UCHAR PageCode : 6;
UCHAR Reserved1 : 2;
UCHAR PageLength;
UCHAR Reserved2 : 6;
UCHAR DCC : 1;
UCHAR DCE : 1;
UCHAR Reserved3 : 5;
UCHAR RED : 2;
UCHAR DDE : 1;
UCHAR CompressionAlgorithm[4];
UCHAR DecompressionAlgorithm[4];
UCHAR Reserved4[4];
} MODE_DATA_COMPRESSION_PAGE, *PMODE_DATA_COMPRESSION_PAGE;

warning C4214: nonstandard extension used : bit field types other than int

I could put a #pragma warning(suppress:4214) in front of every UCHAR, but
is there a better way? /Ze doesn’t work as it’s been deprecated.

Regards, Richard.


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

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 pack

Sent from Surface Pro

From: Jeff Glass
Sent: ‎Thursday‎, ‎August‎ ‎28‎, ‎2014 ‎2‎:‎26‎ ‎PM
To: Windows System Software Devs Interest List

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