News for hackers. Stuff that matters.
Re:What is C in practice? by angersock on Monday June 29, 2015 @03:08PM (#9800203)
To pick your nit, note that they specifically said reading an uninitialized or partially initialized variable, not reading the address of the same.
Re:What is C in practice? by dllthomas on Monday June 29, 2015 @03:41PM (#9800405)
I didn't mean to imply (and don't think I did...) that reading an uninitialized variable is not a problem, just that the problem is entirely unrelated to whether it has a memory location.
Re:What is C in practice? by eatonphil on Monday June 29, 2015 @06:56PM (#9801716)
Hate to ask the stupid question, but I've been wondering and it seems to be along the same lines... Why can't this be valid?

int f; f = 2;

To me this says, there is an int pointer f. Let f point to 2. Is this not possible only because 2 does not occupy memory? I don't see why this couldn't be valid.

Re:What is C in practice? by dllthomas on Monday June 29, 2015 @07:18PM (#9801818)
Assuming you're asking about

    int *f; *f = 2;

The statement,

    *f = 2;
says "dereference f to get a location; set the contents of that location to 2". "Set f to the location of 2" would be spelled

    f = &2;
This is partly a matter of the difference between assignment and definition(/equality).

The first of these is invalid C (undefined behavior) because it uses a value (the contents of f) before initialization.

The second is invalid C (compile error) because 2 is not an l-value (that is, it does not have a location).

Edited to add: I will note that I don't think there is any reason

    *f = 2;
couldn't mean to give f the addess of 2, as by analogy to structural pattern matching, but that the syntax is already taken for something else.