Hi,
(N.B. I know almost nothing, so keep in mind I only barely heard about this stuff.)
> maybe some of you are using mingw32 and/or writing portable code for
> 32/64bit systems so it may save your time on hunting bugs.
C actually doesn't "demand" portable code, nor does GCC. It's within the guidelines of the C language (from Rationale?) to actually write "fast but non-portable code" if needed. (Not everything has to be "strictly conformant", and there are many environmental dependencies that people often overlook, e.g. file name length, temp dirs [if any], size of various things, etc). Portability is often way more complex than just language syntax.
> I just
> recompiled my KMD under new mingw32 4.7.0 and got a crash. After night
> tracking I found that the problem is in size of structure:
>
> __attribute__((packed))
That is not really portable. So you're basically upset that one GCC supports it a certain way while another doesn't. (IIRC, e.g. Bellard's TCC only accepted such a thing on individual struct members, not the overall struct. Not sure what other compilers accept, most seem to accept some form of #pragma pack , but #pragma options are inherently non-standard).
> You may think that __attribute__((packed)) save your ass and will be always
> 6 Bytes.
Needing exact size is rare (network packets??), or at least more rare than otherwise. Most structs (and things like long double) are aligned for better speed. (Some architectures actually demand alignment of all code. x86 only mostly demands it for SSE. I think GCC now assumes or makes sure the stack is 16-byte aligned now, definitely for x86-64, maybe even x86, because of that.)
> Forget, not now, world is going mad and packing behaves
> differently.
> To fix it, it's needed to add -mno-ms-bitfields gcc option since version
> 4.7.0.
> But not at all systems. DJGPP 4.7.1 doesn't need it. But mingw32 and 64-bit
> linux gcc yes.
Earlier today, I just happened to read (for literally no reason beyond curiosity) about (ActiveState) Perl and XS modules and needing a compiler. I have no interest in Windows programming, but I was looking up random stuff about makefiles. Anyways, apparently MinGW and MSVC (since both use MSVCRT) can build compatible code (e.g. XS modules) if you use the (now default) ms-bitfields part. So that's probably GCC's upstream motivation, if I had to take a guess.
You may also want to take a look at C11 (-std=c11 for GCC 4.7.1) alignof, alignas, max_align_t, aligned_alloc (stdalign.h). I'm not 100% aware of the syntax, but it's somewhat restricted, i.e. you can't necessarily decrease an object's alignment (and I'm not sure most object formats let you willy nilly change overall alignment anyways, e.g. DJGPP COFF). |