Argonne National Laboratory

Experimental Physics and
Industrial Control System

2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020  Index 2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020 
<== Date ==> <== Thread ==>

Subject: Re: C strict aliasing rules
From: Andrew Johnson <anj@aps.anl.gov>
To: Eric Norum <norume@aps.anl.gov>
Cc: Core talk list <core-talk@aps.anl.gov>
Date: Mon, 27 Nov 2006 12:23:14 -0600
Eric Norum wrote:

static inline void
writethree(int *p)
{
    short *palias = (short *)p;
   *palias = 3;
}

int
testalias()
{
    int value = 12345678;
    writethree(&value);
    return value;
}

One might expect that the value returned from testalias() would be 12345678 with either its most-significant 16 bits or least- significant 16 bits set to 3 (on most architectures).
....
One would be wrong, though.

I don't think life is quite as bad as it might seem; if you take off the "static inline" keywords from writethree(), I suspect the optimizer may not be able to be quite as aggressive in throwing out code - please experiment and respond to that suggestion.

Since we don't (shouldn't?) have any C routines in base that are marked as "static inline", I don't think our problems are as large as you make out them to be. I suspect the rules for C++ are subtly different, so it would also be interesting to see what using the C++ compiler generates.

- Andrew
--
There is considerable overlap between the intelligence of the smartest
bears and the dumbest tourists -- Yosemite National Park Ranger

Replies:
Re: C strict aliasing rules Eric Norum
References:
C strict aliasing rules Eric Norum

Navigate by Date:
Prev: C strict aliasing rules Eric Norum
Next: Re: C strict aliasing rules Eric Norum
Index: 2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020 
Navigate by Thread:
Prev: C strict aliasing rules Eric Norum
Next: Re: C strict aliasing rules Eric Norum
Index: 2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020 
ANJ, 02 Feb 2012 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·