On 6/22/2010 8:33 AM, Ersek, Laszlo wrote:
> [...]
> Yes, it is positively not "minimal". We started with
>
> a = b = c = 7;
>
> then (after changing types accordingly)
>
> *++a = *++b = *++c = 7;
>
> and then I added the fprintf()'s. There are better ways, probably. Care
> to show one?
If the goal is to show that associativity et al. do not govern
evaluation order, I'd suggest stripping away side-effects that don't
really matter and may just act as red herrings. Something like
#include <stdio.h>
static int index(int idx) {
printf ("idx = %d\n", idx);
return idx;
}
int main(void) {
int array[4] = { 0 };
array[index(1)] = array[index(2)] = array[index(3)] = 7;
printf ("array = { %d, %d, %d, %d }\n",
array[0], array[1], array[2], array[3]);
return 0;
}
.... would be similar in spirit to your original, but without the
distractions of pointers-to-pointers and so on.
--
Eric Sosman
lid