2 ms·
It's exactly like Lisp: (let* ((x (this)) (x (that)) ...) ...) In C you cannot even do: { int x = 42; { int x = x + 1; // x + 1
by kazinator 6y ago
It's exactly like Lisp:
(let* ((x (this))
(x (that))
...)
...)
In C you cannot even do:
{ int x = 42;
{ int x = x + 1; // x + 1 refers to this second x
... } }
This is because the scope of the identifier being declared already starts at the =. So even if the redeclaration were allowed without opening a new block scope, it wouldn't work.
However, there is a good reason for that: initializers can be self-referential, so they have to have their own identifier in scope:
// define circular structure in one step, no assignments:
struct node n = { .next = &n, .prev = &n };
In this regard, the scoping rule is like letrec in Scheme or labels in Common Lisp.