Re: size of pointer variables
- From: rlb@xxxxxxxxxxxxxxxxxxxxxx (Richard Bos)
- Date: Tue, 31 May 2005 07:42:15 GMT
junky_fellow@xxxxxxxxxxx wrote:
> 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 ?
The code is not legal, for a couple of reasons. First, bzero() is not an
ISO C function. Second, you don't initialise pstr_node, so it points
nowhere when you pass it to bzero(). Third, you have a parenthesis too
many (and two superfluous, but harmless ones. BTW, I disagree with
bjrnove on using sizeof (node_t); the way you have it is more solid.).
The cast in itself, though, is legal; everything can be cast to a char
*, which must have the same size and representation as a void *, so like
a void *, it can represent all other kinds of pointers.
It is probably superfluous, though, since the most usual implementations
of bzero() take a void * as their first argument, and you can pass any
object pointer as a parameter declared as void *, without a cast.
Richard
.
- Follow-Ups:
- Re: size of pointer variables
- From: junky_fellow
- Re: size of pointer variables
- 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: how to define a function pointer variable witout typdef?
- Next by Date: Re: size of pointer variables
- Previous by thread: Re: size of pointer variables
- Next by thread: Re: size of pointer variables
- Index(es):
Relevant Pages
|