Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

pointer to struc

vtuneuser
Beginner
350 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
350 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

0 Kudos
jim_dempsey
Beginner
350 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

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