Re: Type-casting void pointers?
- From: Michael Mair <Michael.Mair@xxxxxxxxxxxxxxx>
- Date: Fri, 15 Jul 2005 23:43:19 +0200
hugo2 wrote:
Obrhy/hugo July 12, 2004
Take a look at this memcpy() definition. Is there a good reason the void pointer args are cast to byte just to assign their addresses to byte pointers?
/*from Steve Maguire's 'Writing Soild Code'*/
Did you forget an 'e' or get wrong the order of 'i' and 'l'? SCNR
void *memcpy(void *pvTo,void *pvFrom,size_t size) { byte *pbTo = (byte *)pvTo; byte *pbFrom = (byte *)pvFrom; while(size-- >0) *pbTo++ = *pbFrom++;
return (pvTo); }
The addresses are all unsigned int. Why not simply byte *pbTo = pvTo; to initialize?
In the case of void*, the cast is completely unnecessary. I do not know the definition of the type "byte" but if it is anything other than a typedef for "unsigned char", I would suggest that you have a look at the wisdom to be found in c.l.c rather than believing this book: Unnecessary casts are a Bad Thing.
Cheers Michael -- E-Mail: Mine is an /at/ gmx /dot/ de address. .
- References:
- Type-casting void pointers?
- From: hugo2
- Type-casting void pointers?
- Prev by Date: Re: what I miss?
- Next by Date: Re: Type-casting void pointers?
- Previous by thread: Re: Type-casting void pointers?
- Next by thread: Re: Type-casting void pointers?
- Index(es):
Relevant Pages
|