Unspecified, not undefined
Jonathan Gingerich
jon at maui.cs.ucla.edu
Thu Apr 18 06:51:39 AEST 1991
In article <RJOHNSON.91Apr17102824 at olorin.shell.com> rjohnson at shell.com (Roy Johnson) writes:
>One more shot at this "problem":
>
>int v=1;
>
>int return_v() {
> return v;
>}
>
>int main() {
> printf("v=%d, v=%d\n", v++, return_v());
> return 0;
>}
I don't believe the following sequence is prohibited:
evaluation of (0) args to return_v()
evaluation of return_v
s.p. between evaluation of call and call
evaluation of v++ - reads v
side effect of v++ - writes v using previous read
call to return_v() - reads v
...
This would make it undefined.
>Or how about using aliasing:
>
>int main() {
> int v=1, *pv=&v;
>
> printf("v=%d, v=%d", v++, *pv);
> return 0;
>}
Again, read and separated write of the same location would make it undefined,
and there are no s.p.'s in question - undefined.
I believe any unordered asymetric operation combined with function calls
(not macros!-) can be unspecified.
int v=1;
int bump_v() {
return ++v;
}
int main() {
... (bump_v() - bump_v()) ...
}
Jon.
More information about the Comp.std.c
mailing list