This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: does this code break the strict-aliasing rules ?
- From: Andrew Haley <aph at redhat dot com>
- To: Michael Haubenwallner <michael dot haubenwallner at salomon dot at>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 6 Feb 2007 16:02:37 +0000
- Subject: Re: does this code break the strict-aliasing rules ?
- References: <1170777494.30181.38.camel@sapc154>
Michael Haubenwallner writes:
> encountering strange results, I'm unsure whether this code is affected
> by strict-aliasing rules:
>
> static void *CreateRes(PrexecTresource eRes, void *pvVal)
> {
> switch(eRes) {
> case PrexecNprintCommand:
> case PrexecNoptHost:
> case PrexecNoptHostString:
> case PrexecNoptDest:
> case PrexecNoptDestString:
> case PrexecNoptFileString:
> if (pvVal != NULL) {
> pvVal = (void*)strdup((char*)pvVal);
> }
> break;
> default:
> break;
> }
>
> return pvVal;
> }
>
> Specifically the casts around the 'strdup'...
This particular code isn't, no. char* can legally alias with
everything.
Andrew.