Re: Undefined behaviour when modifying the result of an assignment operator



Andy Lomax <abuse@[127.0.0.1]> wrote [quoting the C standard]:
>
>>If an attempt is made to modify
>>the result of an assignment operator or to access it after the next sequence point, the
>>behavior is undefined.
>
> What does this actually mean? Can anyone give me a code example that
> leads to undefined behaviour?

struct { int a[2]; } s, t;
int *p;

(s = t).a[0] = 3; // attempting to modify the result of an assignment op.
p = (s = t).a;
p[0]; // attempting to access the result after the next s.p.

-Larry Jones

Hmph. -- Calvin
.



Relevant Pages

  • Re: selective access to different classes
    ... in it are set from outsite your SoundDataHolder. ... the system in a sequence of processing steps and data formats for each ... operate in turns call each operaion in sequence, passing only those ... parameters which they modify. ...
    (comp.object)
  • Re: modify PVA.pl (z/OS and perl-5.8.6)
    ... This contains a sequence of property aliases ('ea' for EastAsianWidth, 'jt' for JoiningType and so on) and their corresponding values. ... I changed the order of propertynames in PVA_abbr_map, but perl -d still continues to follow the original sequence of property names and exits before 'ea' is used. ... I tried to modify PVA.pl manually on the linux box to to see if perl ran with this new sequence, so that the 'ea' case would be picked up before perl -d had a chance to exit. ...
    (perl.beginners)
  • Re: string upper, string lower, string subthisforthat
    ... Non-modifying sequence operations ... So I read it that the function object cannot modify the sequence ... "25.1 Non-modifying sequence operations". ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Bizzare lst length problem
    ... and so was casting to a string as a stopgap measure that I then forgot ... def function: ... # modify the sequence ...
    (comp.lang.python)
  • Re: modifying mutable list elements in a for loop
    ... > The python tutorial tells me "It is not safe to modify the sequence ... But what if my list elements are ... > sequence which is being looped over. ...
    (comp.lang.python)

Loading