Click here to Skip to main content
15,887,436 members
Home / Discussions / C#
   

C#

 
GeneralRe: Quick Q: How big is a bool value? Pin
PIEBALDconsult31-Aug-07 14:32
mvePIEBALDconsult31-Aug-07 14:32 
GeneralRe: Quick Q: How big is a bool value? Pin
Scott Dorman31-Aug-07 15:48
professionalScott Dorman31-Aug-07 15:48 
GeneralRe: Quick Q: How big is a bool value? Pin
Luc Pattyn31-Aug-07 16:02
sitebuilderLuc Pattyn31-Aug-07 16:02 
GeneralRe: Quick Q: How big is a bool value? Pin
Scott Dorman31-Aug-07 16:24
professionalScott Dorman31-Aug-07 16:24 
GeneralRe: Quick Q: How big is a bool value? Pin
Luc Pattyn1-Sep-07 0:55
sitebuilderLuc Pattyn1-Sep-07 0:55 
GeneralRe: Quick Q: How big is a bool value? Pin
PIEBALDconsult1-Sep-07 5:08
mvePIEBALDconsult1-Sep-07 5:08 
GeneralRe: Quick Q: How big is a bool value? Pin
PIEBALDconsult31-Aug-07 16:08
mvePIEBALDconsult31-Aug-07 16:08 
GeneralRe: Quick Q: How big is a bool value? Pin
Scott Dorman31-Aug-07 16:21
professionalScott Dorman31-Aug-07 16:21 
PIEBALDconsult wrote:
C#, Visual Basic. NET, and C++ compilers apply the Sequential layout value to structures by default.


Yes, but...according to the MSDN docs:

The members of the object are laid out sequentially, in the order in which they appear when exported to unmanaged memory. The members are laid out according to the packing specified in StructLayoutAttribute.Pack, and can be noncontiguous.
And the docs for StuctLayoutAttribute.Pack say:
This field indicates the packing size that should be used when the LayoutKind.Sequential value is specified. The value of Pack must be 0, 1, 2, 4, 8, 16, 32, 64, or 128. A value of 0 indicates that the packing alignment is set to the default for the current platform.

The default packing size is 8, except for unmanaged structures that typically have a default packing size of 4.
So, it sounds like as long as the struct stays inside managed code, the fields are packed along an 8 byte boundary, but if the struct is exported to unmanaged code and has LayoutKind.Sequential set it is exported in the order in which they appear in the definition.

It definately seems like they could have made the explanation a lot clearer.




Scott.

—In just two days, tomorrow will be yesterday.

[Forum Guidelines] [Articles] [Blog]

GeneralRe: Quick Q: How big is a bool value? Pin
PIEBALDconsult31-Aug-07 16:39
mvePIEBALDconsult31-Aug-07 16:39 
JokeRe: Quick Q: How big is a bool value? Pin
PIEBALDconsult31-Aug-07 14:40
mvePIEBALDconsult31-Aug-07 14:40 
QuestionCapturing Key Down Events in MenuStrip Pin
paas31-Aug-07 5:17
paas31-Aug-07 5:17 
QuestionRadioButton and CheckBox confusion... Pin
solutionsville31-Aug-07 4:44
solutionsville31-Aug-07 4:44 
AnswerRe: RadioButton and CheckBox confusion... Pin
PIEBALDconsult31-Aug-07 4:58
mvePIEBALDconsult31-Aug-07 4:58 
GeneralRe: RadioButton and CheckBox confusion... Pin
solutionsville31-Aug-07 5:23
solutionsville31-Aug-07 5:23 
GeneralRe: RadioButton and CheckBox confusion... Pin
PIEBALDconsult31-Aug-07 9:37
mvePIEBALDconsult31-Aug-07 9:37 
Questionconvert image to Byte Pin
TAREQ F ABUZUHRI31-Aug-07 4:29
TAREQ F ABUZUHRI31-Aug-07 4:29 
AnswerRe: convert image to Byte Pin
pmarfleet31-Aug-07 4:38
pmarfleet31-Aug-07 4:38 
GeneralRe: convert image to Byte Pin
TAREQ F ABUZUHRI31-Aug-07 4:40
TAREQ F ABUZUHRI31-Aug-07 4:40 
GeneralRe: convert image to Byte Pin
Steve Hansen31-Aug-07 4:41
Steve Hansen31-Aug-07 4:41 
GeneralRe: convert image to Byte Pin
leppie31-Aug-07 5:06
leppie31-Aug-07 5:06 
GeneralRe: convert image to Byte Pin
TAREQ F ABUZUHRI31-Aug-07 9:49
TAREQ F ABUZUHRI31-Aug-07 9:49 
GeneralRe: convert image to Byte Pin
Mairaaj Khan1-Sep-07 1:32
professionalMairaaj Khan1-Sep-07 1:32 
Questionerror Array Pin
TAREQ F ABUZUHRI31-Aug-07 4:26
TAREQ F ABUZUHRI31-Aug-07 4:26 
AnswerRe: error Array Pin
Steve Hansen31-Aug-07 4:42
Steve Hansen31-Aug-07 4:42 
QuestionGeneric Error While running in localhost without port Pin
MahiRaju31-Aug-07 3:49
MahiRaju31-Aug-07 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.