Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Please explain me this C declaration

Status
Not open for further replies.

bittware

Full Member level 4
Joined
Apr 3, 2004
Messages
208
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,296
Activity points
1,986
A weird C declaration

Could anyone help me to understand what's meaning by the C declaration below?

typedef struct QFreeBlockTag QFreeBlock;
struct QFreeBlockTag {
QFreeBlock *next;
};

I am wondering how the compiler get the clue about what type the pointer points to.

Thanks for your help in advance.
 

sshahid47

Full Member level 1
Joined
Nov 5, 2004
Messages
99
Helped
15
Reputation
30
Reaction score
2
Trophy points
1,298
Activity points
974
A weird C declaration

Hi,
what we have here is a simple pointer to its own type and for the compiler, all it has to do is allocate the size required to hold an address(4 bytes), however if you would have

typedef struct QFreeBlockTag QFreeBlock;
struct QFreeBlockTag {
QFreeBlock next;
};

the comiler would throw an error coz the comiler does not know how much to allocate, but for the pointer case it knows that all it has to do is allocate so much to hold the address.

hope that cleared it up.
 

    bittware

    Points: 2
    Helpful Answer Positive Rating

alitavakol

Member level 2
Joined
Dec 1, 2005
Messages
47
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Location
Iran
Activity points
1,653
Re: A weird C declaration

this is not matter what pointer to use. for each pointers, compiler allocates 4 bytes of memory;
also the size of the overall structure(which contains 4 bytes of pointer variable) determines the required thinks for arithmetic operations on pointer variables.
 

Zhasha

Junior Member level 3
Joined
Dec 3, 2005
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Denmark
Activity points
1,643
Re: A weird C declaration

this structure can basically be used as an empty linked list
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top