This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: does this code break the strict-aliasing rules ?


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]