EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Problems with Dynamic Array population
From: Benjamin Franksen <[email protected]>
To: "Brown, David L." <[email protected]>
Cc: EPICS tech-talk <[email protected]>
Date: Sun, 9 Nov 2014 03:46:11 +0100
Am Freitag, 7. November 2014, 17:02:53 schrieben Sie:
> I got around the problem.  I don’t know why this is, but when one defines
> an array size of 7 elements (like as seen below), assigns them to an array
> of three elements outside the state machine, and then reassigns the
> elements inside the state machine, there is no core dump.

I understand the problem now. What you failed to realize is that in SNL an
array like your

double MPS[7];

can be assigned either wholesale to a *single array-valued* channel, like you
did in your original program (which I failed to notice at first):

assign MPS to "";

Or it can be assigned element by element to *multiple scalar channels*:

assign MPS to {};

as in your new code. The curly braces really do make the difference here! The
assign clause ultimately fixes which of the two possibilities is selected and
calls to the pvAssign function have to follow it.

BTW1, if you re-assign all the elements using pvAssign anyway, the number of
channel names inside the curly braces does not matter (as long as it is not
greater than the number of elements in the array), so you can just leave them
out completely as in the code above.

BTW2, this is SNL, not C. The two are similar but not the same. There is
nothing like the assign clause in C and though the syntax resembles the one
for C initializers, the effect is something rather different.

The bug in the (ancient) sequencer version you are using is that the compiler
(snc) does not check what kind of assign you made when it sees the pvAssign
call; instead it assumes the pvAssign is consistent with the assign clause --
which was not the case. So the run-time implementation of pvAssign went wrong
and tried to access a non-existing channel object for MPS[n] with n > 0 which
in turn led to memory corruption.

Cheers
Ben
--
"Make it so they have to reboot after every typo." -- Scott Adams


________________________________

Helmholtz-Zentrum Berlin für Materialien und Energie GmbH

Mitglied der Hermann von Helmholtz-Gemeinschaft Deutscher Forschungszentren e.V.

Aufsichtsrat: Vorsitzender Prof. Dr. Dr. h.c. mult. Joachim Treusch, stv. Vorsitzende Dr. Beatrix Vierkorn-Rudolph
Geschäftsführung: Prof. Dr. Anke Rita Kaysser-Pyzalla, Thomas Frederking

Sitz Berlin, AG Charlottenburg, 89 HRB 5583

Postadresse:
Hahn-Meitner-Platz 1
D-14109 Berlin

http://www.helmholtz-berlin.de


References:
Problems with Dynamic Array population Brown, David L.
Re: Problems with Dynamic Array population Brown, David L.

Navigate by Date:
Prev: RE: Asyn and stringin records Mark Rivers
Next: Re: Permissible in C to call CA I/O functions from callback? Benjamin Franksen
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Problems with Dynamic Array population Brown, David L.
Next: compiling issues during building cothread Jeong Han Lee
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 17 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·