Re: More issues


Subject: Re: More issues
From: Michael McNamara (mac@verisity.com)
Date: Mon Dec 30 2002 - 10:54:08 PST


Karen Pieper writes:
> >>Wouldn't this outlaw 'word = mem[i++];'
> >This would outlaw 'word = mem[i++] + mem[i++];', '--i++', and 'i = i++;'
> >I'm hoping the person who said this will speak up. I don't remember who or
> >exactly what they said. A statement unit is something like a statement not
> >including the statements that might be part of function calls within the
> >statement.
>
> I do not have a copy of the ANSI C standard definition in front of
> me, so I cannot give you the exact wording, but the idea is that a
> statement can assign only once to a single variable. Brad, can you
> look up the wording again?
>
> The proposal I sent out for auto-increment allows tools the option
> of issuing an error in the event of multiple assignments, but does
> not require tools to do so. For synthesis, I believe this is a
> good restriction because it ensures that two different
> interpretations of a statement (Formal and Synthesis) will get the
> same values.
>

Hmm, well I've never heard of that restriction (have you looked at
YACC generated C code recently?), but I do have a K&R second edition
[With ANSI C] here, and the only thing close to such a restriction
that it has is that it is the case that while it is stated that

  a += b;

  is logically equivalent to

  a = a + b;

  only 'a' is evaluated once. This matters given:

  mem[f(b)] += 1;

as evaluating f(b) could have side effects (or even yeild different
answers) if evaluated more than once.

Testing the assumption that ANSI C disallows multiple assignments, and
that GCC enforces this, with gcc (v 2.95.2) I see:

main(int argc, char **argv)
{
 int i;
 i = 10;
 printf("I is %d\n",i);
 i += ++i * --i;
 printf("I is %d\n",i);
  
}
and get (on linux)
$ a.out
I is 10
I is 110

on HP
$ gcc -O3 foo.c
$ a.out
I is 10
I is 110

$ gcc foo.c
$ a.out
I is 10
I is 120

So clearly there are ambiguity issues with expression evaulation order
and multiple assignments to the same variable in a single statement;
but multiple assignments themselves appear to be allowed in C.

-mac



This archive was generated by hypermail 2b28 : Mon Dec 30 2002 - 10:54:51 PST