Continue to Site

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
1
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.
 

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
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.
 

Re: A weird C declaration

this structure can basically be used as an empty linked list
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top