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: Eric Norum <norume@aps.anl.gov>
To: Marty Kraimer <mrkraimer@comcast.net>
Cc: Kay-Uwe Kasemir <kasemirk@ornl.gov>, Core talk list <core-talk@aps.anl.gov>
Date: Tue, 28 Nov 2006 09:37:18 -0600

On Nov 28, 2006, at 9:23 AM, Marty Kraimer wrote:

Kay-Uwe Kasemir wrote:

Hi:

Do I understand correctly that the most likely impact for EPICS might be this type of code:

struct xyz_regs
{
    Word control;
    Word status;
    ...
}

void xyz_operate(char *vme_base)
{
    struct xyz_regs *xyz = (struct xyz_regs *) vme_base;

    xyz->control = 0x1234;
    if (xyz->status & 0x8000)
      ....
}

The mapping of C structures to hardware registers?


volatile should be used for all access to hardware registers.
volatile prevents compiler optimization.

Let's not get off on a tangent here. The problem Kay was describing was one of structure padding, alignment, endianness when using a structure to define the layout of hardware registers. The issue on the table is that of compilers imposing their strict aliasing rules, and what to do about that.

--
Eric Norum <norume@aps.anl.gov>
Advanced Photon Source
Argonne National Laboratory
(630) 252-4793



Replies:
Re: C strict aliasing rules Kay-Uwe Kasemir
References:
C strict aliasing rules Eric Norum
Re: C strict aliasing rules Benjamin Franksen
Re: C strict aliasing rules Eric Norum
Re: C strict aliasing rules Benjamin Franksen
Re: C strict aliasing rules Kay-Uwe Kasemir
Re: C strict aliasing rules Marty Kraimer

Navigate by Date:
Prev: Re: C strict aliasing rules Marty Kraimer
Next: Re: C strict aliasing rules Kay-Uwe Kasemir
Index: 2002  2003  2004  2005  <20062007  2008  2009  2010  2011  2012  2013  2014  2015  2016  2017  2018  2019  2020 
Navigate by Thread:
Prev: Re: C strict aliasing rules Marty Kraimer
Next: Re: C strict aliasing rules Kay-Uwe Kasemir
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 ·