LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   GCC compile problem:struct A have a member variable which is just a struct type name? (https://www.linuxquestions.org/questions/programming-9/gcc-compile-problem-struct-a-have-a-member-variable-which-is-just-a-struct-type-name-636120/)

leon.zcom 04-17-2008 08:45 PM

GCC compile problem:struct A have a member variable which is just a struct type name?
 
my code is as follow:

typedef struct a
{
uint32_t ulMsgType;
} a;

typedef struct b
{
a;
uint32_t ulIfCount;

} b;

b *pb;

if my code use pb->ulMsgType, then GCC (4.1.1 20061011) cannot compile it ,it will output an error that struct b doesn't have member "ulMsgType".

But if I run the code in a cross-compile environment, just like hardhat3.0, using xscale_be-gcc(3.2.1 20020930), the code can be compiled successfully.

So my questions is what should i do to make it compile successfully?

Whether I could add some options for GCC (4.1.1 20061011) to fix the problem, if so, what options should I add?


-------------------------
OS: 2.6.18-1.2798.fc6

JMJ_coder 04-17-2008 09:04 PM

Hello,

Try changing pb->ulMsgType to pb->a.ulMsgType

leon.zcom 04-17-2008 09:20 PM

I have fix the problem,

GCC need add a option "-fms-extensions".

osor 04-18-2008 04:40 PM

Let me point out that although it “works”, this is not standards-compliant behavior. In fact, the correct thing to do is to name your field so you can refer to it directly.


All times are GMT -5. The time now is 04:26 AM.