次のコードスニペットは、gccを使用するMac OS Xで正常にコンパイルされますが、lcc-win32を使用するWindowsではコンパイルできません。
typedef struct Foo Foo;
typedef struct Bar Bar;
struct Bar { int age; int height; };
struct Foo { Bar barOne; Bar barTwo; };
// Elsewhere, in some function:
Bar barOne = { 2, 4 };
Bar barTwo = { 6, 8 };
Foo instance = { barOne, barTwo };
そして、このエラーを出します:
見つかった'structBar'期待される'int'
このように構造体を初期化することで、これを「克服」できます。
Foo instance = { barOne.age, barOne.height, barTwo.age, barTwo.height };
So, I understand what's going on... but I feel like this makes my code a lot more complex (I need to understand the implementation and layout of the other structs I'm using, instead of simply consuming them - and if that layout changes, I have to spider that change out to anyone else using the struct).
I'm wondering if LCC is being either "more strict" (adhering to some standard) or "more dumb" (the compiler is too dumb to handle this situation).
Thanks.
Also, please see my other LCC-Win32 question: LCC: Forward Declaration of Typedef'd Enum Failing?