Q:

Size of bool in exported C function vs struct vs .Net marshaling

I'm not sure if this is a problem, but certainly a curiosity. I have a C DLL that exports a function taking a 32-bit integer and a boolean (stdbool.h). The exported function (stdcall) indicates the parameter list is 8 bytes (4-byte int, 4-byte bool). This C DLL also contains a structure that uses booleans. Checking sizeof(bool) indicates 1-byte booleans.
I have a .Net wrapper for this native DLL. When marshaling the structure, I specified for each boolean field UnmanagedType.U1 and all works well, everything is aligned correctly. I only used sequential layout, not explicit nor any offsets nor any packing.
My question is, why the apparent disparity in boolean size?

A:

All function parameters in C that are smaller than "int" are converted to "int" size in the call. This is because each parameter is placed on the stack separately (in most architectures), so they are converted to stack cell size which is usually equal to size of "int".
As for structure - nothing is converted. Though we should not forget about alignment in structures. But this is another story.

