public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* does this code break the strict-aliasing rules ?
@ 2007-02-06 15:58 Michael Haubenwallner
  2007-02-06 16:02 ` Andrew Haley
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Haubenwallner @ 2007-02-06 15:58 UTC (permalink / raw)
  To: gcc-help

Hi,

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'...

Thanks,
  /haubi/


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: does this code break the strict-aliasing rules ?
  2007-02-06 15:58 does this code break the strict-aliasing rules ? Michael Haubenwallner
@ 2007-02-06 16:02 ` Andrew Haley
  0 siblings, 0 replies; 2+ messages in thread
From: Andrew Haley @ 2007-02-06 16:02 UTC (permalink / raw)
  To: Michael Haubenwallner; +Cc: gcc-help

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-02-06 16:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-06 15:58 does this code break the strict-aliasing rules ? Michael Haubenwallner
2007-02-06 16:02 ` Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).