Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.

pointer to struc

vtuneuser
Beginner
177 Views
Is there any differencein the size of a variable of the followingtwo types?
1) struct node
{
long num;
char *c_ptr;
struct node *pred, *child;
int score;
}
2) typedef struct node *node_p;
struct node
{
long num;
char *c_ptr;
node_p *pred, *child;
int score;
}
Does the first declaration of struct "node" have more bytes in size?
0 Kudos
3 Replies
Maximillia_D_Intel
177 Views

Hi,

I wouldn't expect there to be a difference. What happens when you try a small testcase and use sizeof() and compare the size of two objects, one using the first decl and the other the second?

Max

jim_dempsey
Beginner
177 Views

Although the size of the two structs are the same the contexts are different.

In the first example pred and child are pointers to "struct node". In the second example pred and child are pointers to pointers to"struct node".To beequivilent you need to take the "*" off of the pred and child in the 2nd case because node_p already declares a pointer and not the struct node.

Jim Dempsey

vtuneuser
Beginner
177 Views
oh, yes, I should not have "*" in front of pred and child, I tested it and both structs have the same size. Thanks.
Reply