tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: why cast to char* through void*



In article <m1MM5sb-000kmuC%most.weird.com@localhost>,
Greg A. Woods <tech-userlevel%NetBSD.org@localhost> wrote:
>-=-=-=-=-=-
>
>Either I have a brain-block, or I'm missing something, or...
>
>A long time ago I suggested to myself in a comment in login_cap.c that
>the pointer arithmetic in setuserenv() should be replaced with an array
>reference and thus avoid a lot of ugliness.
>
>I see that's been done now, but the cast to char* through void* remains.
>
>It doesn't make any sense to me -- there shouldn't be any alignment
>work-arounds necessary here (should there?), and I see no other possible
>reason for it.
>
>
>--- login_cap.c        10 Feb 2007 12:57:39 -0500      1.25
>+++ login_cap.c        01 Jul 2009 15:14:06 -0400      
>@@ -517,8 +517,8 @@
>       if (!res)
>               return -1;
>       
>-      ptr = (char *)(void *)&res[count];
>-      (void)strcpy(ptr, str);
>+      ptr = (char *) &res[count];
>+      (void) strcpy(ptr, str);
> 
>       /* split string */
>       for (i = 0; (res[i] = stresep(&ptr, stop, '\\')) != NULL; )
>

Typically used to shut up gcc type punning warnings. Not that it is the TRTTD
in all cases. Does anyone know if this makes gcc produce "the wanted" code
(has the effect of -fno-strict-aliasing) or it just shuts up the warning?

christos



Home | Main Index | Thread Index | Old Index