Archived

This topic is now archived and is closed to further replies.

Tiger99

struct

Recommended Posts

Tiger99    122
Hello Does anyone know what''s the problem of the following declarting of struct? I am getting a redefiniation of struct pcb error Thanks #define PCB struct pcb PCB { PCB *ptr; char *name; UINT32 id; UINT32 flag; UINT32 program_counter; // DATA REGISTER UINT32 reg_D0; UINT32 reg_D1; UINT32 reg_D2; UINT32 reg_D3; UINT32 reg_D4; UINT32 reg_D5; UINT32 reg_D6; UINT32 reg_D7; // ADDRESS REGISTER UINT32 reg_A0; UINT32 reg_A1; UINT32 reg_A2; UINT32 reg_A3; UINT32 reg_A4; UINT32 reg_A5; UINT32 reg_A6; UINT32 reg_A7; UINT32 process_state; UINT32 priority; MSG_ENV *msg_ptr_head; MSG_ENV *msg_ptr_tail; };

Share this post


Link to post
Share on other sites
brass_fish    122

#define PCB struct pcb

PCB
{
PCB *ptr;


this expands to


struct pcb
{
struct pcb *ptr;


your redefining the struct inside the struct


extended waranty, how can I lose!

[edited by - brass_fish on March 15, 2003 10:50:12 PM]

[edited by - brass_fish on March 15, 2003 10:51:21 PM]

Share this post


Link to post
Share on other sites
Sneftel    1788
I could be wrong about this (it''s been a while since I looked at the C standard) but I don''t think compilers are required to allow pointers to incomplete types. Try sticking "struct pcb;" before your definition, and see if that fixes it.


But... but that''s what HITLER would say!!

Share this post


Link to post
Share on other sites
SiCrane    11839
C compilers are required to support pointers to incomplete types (Section 6.2.5 paragraph 19 in the C99 standard (well the final draft anyway)). btw, inserting struct pcb; before it''s definition doesn''t change the fact that is an incomplete type inside the definition.

As far as I can tell, unless your definitions of UINT32 and MSG_ENV are really screwy, your declaration is fine by itself. Emphasis on by itself . If you have in a header file and forgot inclusion guards it could cause problems.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You guys don''t know shit!!!
so BS...

and your extended warranty sucks...

Share this post


Link to post
Share on other sites