Re: size of pointer variables



> 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

.



Relevant Pages

  • Re: Strange problem on GCC - PLEASE HELP!!
    ... be a pointer to char, and you are passing pointer to unsigned char. ... Do not pass pointers to character arrays that are not strings to ...
    (comp.lang.c)
  • Re: Problem with va_ macros and arrays of arrays
    ... > the arrays passed to a ... > specific char, somewhat similar to what the standard function ... that with an array of struct, or possibly a pointer to a dynamic array ... > As I'm still a beginner in C without a copy of the standard I ...
    (comp.lang.c)
  • Re: Insufficient guarantees for null pointers?
    ... will the compiler know what the bounds are after converting that char * ... to an int *, if it could point to either of two arrays which happen to ... compares equal to the original pointer. ...
    (comp.std.c)
  • Re: Q: Trouble with wsprintf
    ... to a pointer to unsigned char. ... signed char, unsigned char, and "plain" char, defined without either ...
    (alt.comp.lang.learn.c-cpp)
  • Re: managed c++ pinned pointer cast
    ... plain char is a different type from unsigned char. ... Pointer to plain char and pointer to unsigned char do not automatically convert to each other. ...
    (microsoft.public.dotnet.languages.vc)