Re: size of pointer variables
- From: "bjrnove" <bjrnove@xxxxxxxxx>
- Date: 30 May 2005 23:44:31 -0700
> typedef struct node {
> long l;
> int i ;
> short s1;
> short s2;
> char c;
>
>
> }node_t;
>
>
> node_t * pstr_node;
> bzero(((char *)pstr_node, sizeof (*pstr_node));
>
>
> Is this legal ? Can we typecast structure pointer to char pointer ?
Yes, it is. I would prefere sizeof(node_t), but it really doesn't
matter. I do not know what bzero does (not standard c), but I presume
the call above would be the same as memset(pstr_node, 0x00,
sizeof(node_t)). In your code above though, it will crash since your
pointer points to garbage. I would recomend you to use unsigned char
when you make your own functions like bzero, because char could be both
signed and unsigned (that's up to your compiler).
--
bjrnove
.
- References:
- size of pointer variables
- From: junky_fellow
- Re: size of pointer variables
- From: Malcolm
- Re: size of pointer variables
- From: junky_fellow
- size of pointer variables
- Prev by Date: Re: Clear doubts regarding the C++ Runtime
- Next by Date: Re: multidimensional arrays and pointers
- Previous by thread: Re: size of pointer variables
- Next by thread: Re: size of pointer variables
- Index(es):
Relevant Pages
|