Re: memset doubt
- From: Barry Schwarz <schwarzb@xxxxxxxxx>
- Date: Tue, 30 Aug 2005 23:25:14 -0700
On 30 Aug 2005 22:43:54 -0700, "srivatsan_b" <srivatsanbs@xxxxxxxxx>
wrote:
>Hi,
>
>Can somebody explain whether an explicit typecast is mandatory while
>calling memset function for a structure? like in the following code
>snapshot.....
> struct some_structure x;
> memset((some_structure*)&x,0,sizeof(some_structure));
>Will memset(&x,0,sizeof(some_structure)); cause some issues?
>
Firstly, &x already has type pointer to struct some_structure.
Therefore, casting any value to the same type it already has is by
definition redundant.
Secondly, memset expects the first argument to have type pointer to
void. If you were going to cast the value, that is what you would
cast it to.
Thirdly, pointer to void is "compatible" with any other unqualified
object pointer type. This means that the compiler can implicitly
convert one to the other whenever it needs to without requiring a
cast.
The only problem with your final question is that for C89 compilers
the cast must include the keyword struct. The use of the structure
tag without the keyword did not become standard until C99 and there
are very few compilers of that grade in use.
<<Remove the del for email>>
.
- Follow-Ups:
- Re: memset doubt
- From: Keith Thompson
- Re: memset doubt
- References:
- memset doubt
- From: srivatsan_b
- memset doubt
- Prev by Date: Re: compare a large number of variables
- Next by Date: Re: memset doubt
- Previous by thread: Re: memset doubt
- Next by thread: Re: memset doubt
- Index(es):
Relevant Pages
|