Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-17-2008, 08:45 PM   #1
LQ Newbie
Registered: Apr 2008
Posts: 15

Rep: Reputation: 0
Question 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
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
Old 04-17-2008, 09:04 PM   #2
Registered: Apr 2006
Distribution: Fedora
Posts: 478

Rep: Reputation: 30

Try changing pb->ulMsgType to pb->a.ulMsgType
Old 04-17-2008, 09:20 PM   #3
LQ Newbie
Registered: Apr 2008
Posts: 15

Original Poster
Rep: Reputation: 0
I have fix the problem,

GCC need add a option "-fms-extensions".
Old 04-18-2008, 04:40 PM   #4
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 76
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
g++ doesn't support "C-struct member initialization" extension of gcc? ta0kira Programming 8 04-13-2008 02:57 PM
Problem with extern struct object, in header file. Undefined type. RHLinuxGUY Programming 7 07-24-2006 12:01 AM
g++ and wrong struct member addresses / struct size misreporting sonajiso Linux - General 5 05-22-2004 10:16 PM
switch statement converting struct char to struct int oceaneyes2 Programming 2 12-10-2003 04:30 PM
using struct type X as pointer in struct X. worldmagic Programming 1 10-28-2003 02:06 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:34 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration