In <[🔎] 200906171751.13989.v13@v13.gr>, Stefanos Harhalakis wrote: >On Wednesday 17 June 2009, Eduardo M KALINOWSKI wrote: >> On Ter, 16 Jun 2009, Stefanos Harhalakis wrote: >> > [snip] >> > 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. >There was a typo. Instead of: >int n=1; int main() { n=n; printf("%d", n); } >it should be: >int n=1; int main() { int n=n; printf("%d", n); } > >Hope this clears things. Yeah, and I don't think you *have* to read the C standard to understand why this doesn't work. Scoping rules are often covered in quick-start guides, and they would include the statement that 'a local variable's scope begins at the *start* of it's declaration and ends at the end of the containing block' with the specific admonition that 'int n = n;' "initializes" n to whatever value was at that location before n was initialized, leaving n with an unknown, not well-defined value. -- Boyd Stephen Smith Jr. ,= ,-_-. =. bss@iguanasuicide.net ((_/)o o(\_)) ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-' http://iguanasuicide.net/ \_/
Attachment:
signature.asc
Description: This is a digitally signed message part.