In <[email protected]>, Eduardo M KALINOWSKI wrote: >On Ter, 16 Jun 2009, Stefanos Harhalakis wrote: >> Of course you need to look at the C spec to >> claim that you understand C in depth (you did... didn't you?) and in >> order to understand why >> >> int n=1; int main() { n=n; printf("%d", n); } >> >> will not output '1' > >I couldn't figure why it wouldn't output 1, so I tried (with gcc >4.2.3) and it did print "1". > >So I'm still curious why you say it would not work. Care to explain?
The 'n=n' statement is the most suspect statement. I suspected it might
have sequence-point issues, since it both reads and object and writes and
object. However, 6.5.2 which deals with sequence points in expressions does
not make this statement invalid because "the prior value [is] read only to
determine the value to be stored".
While the footnotes are not normative, the standard does show "a[i] = i" as
a valid statement. Here's an example of using that statement to basically
do "n=n":
int a = 0; void **i = &i; int main() { a[i] = i; printf("%p", i); }
There may be other issues that affect the quoted code, but I don't see them
off-hand.
--
Boyd Stephen Smith Jr. ,= ,-_-. =.
[email protected] ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/ \_/
signature.asc
Description: This is a digitally signed message part.

