On Mar 8, 9:00*am, Francois Grieu <fgr...@gmail.com> wrote:
> On 08/03/2011 17:23, Chad wrote:
>
>
>
> > On Mar 8, 7:18 am, Kenneth Brody <kenbr...@spamcop.net> wrote:
> >> On 3/7/2011 12:00 PM, Mark Bluemel wrote:
>
> >>> On 03/07/2011 04:41 PM, Francois Grieu wrote:
> >>>> On 07/03/2011 17:33, Mark Bluemel wrote:
> >>>>> On 03/07/2011 04:05 PM, Francois Grieu
> >>>>>> Hi, the subject sums it all.
>
> >>>>>> extern volatile unsigned r;
> >>>>>> unsigned x,y;
>
> >>>>>> void test(void)
> >>>>>> {
> >>>>>> x=r=y;
> >>>>>> }
> >> [...]
> >>>>> so there is no need for r to be read.
>
> >>>> I'm unsure of that, and of if "no need" translates to "no read".
> >>>> My problem boils down to: is the value of (r=y)
> >>>> - the value read from y (that gets written into r).
> >>>> - the value read from r (after?) writing the value of y into r.
> >>>> - any of the above.
> >>>> - other..
>
> >>>http://www.open-std.org/jtc1/sc22/wg...docs/n1256.pdf
> >>> 6.5.16 paragraph 3
> >>> .... An assignment expression has the value of the left operand afterthe
> >>> assignment ....
>
> >>> I see no mention of other operations after the assignment.
>
> >> Consider the fact that, with a volatile, the "value of the left operand
> >> after the assignment" might not necessarily be the value that was just
> >> assigned to it.
>
> > Would this be because the assignment produces a side effect?
>
> A common example is a register r where some (or all) bits are always
> read as 0, regardless of what's written to.
>
I was think of something like the following....
#include <stdio.h>
int main(void)
{
int a = 5;
int b = 9;
int k = a++ + ++b;
printf("The value of k is: %d\n", k);
printf("a = %d and b = %d\n", a, b);
return 0;
}
[cdalten@localhost oakland]$ gcc -Wall -Wextra -Wshadow side.c -o side
[cdalten@localhost oakland]$ ./side
The value of k is: 15
a = 6 and b = 10
[cdalten@localhost oakland]$
This is how I would attempt to explain the example...
In this case, the value of 'b' is incremented by 1. Then this value,
which is now 10, is added the value of 'a' (which is still 5), to
produce a value of 16. The side effect would be the result of applying
the postincrement operator to 'a'. The result of this side effect is
that the value of 'a' is increased by one. Which would happen after
the sequence point?
Or something along those lines. I'm pretty sure the regulars will
correct me.
Chad