| > If `c` does not depend on `a`, then the re-arrangement seems simple: Define `c` later. How does that prevent 'a' from being in the scope where 'c' is defined? It is not clear to me what you mean by defining 'c' later. Later where? And how do we ensure that 'a' is not accessible there? I think lex-lightning's comment has a point. We need to define 'a' and we need to define 'c' and then we need to print 'c' before printing 'a', so although 'c' does not depend on 'a', we still need to keep 'a' in scope because we cannot print it before we print 'c'. Perhaps a convoluted solution to the problem posed in lex-lightning's comment would be something like this: #include <stdio.h>
int getint() {
return 42;
}
int main()
{
int a = getint();
int b = getint() + a;
int c;
{
// Shadow 'a' here to make the outer 'a' inaccessible in this scope.
int *a = NULL;
(void) a;
c = getint();
}
int d = b / c;
printf("%d\n", d);
printf("%d\n", c);
printf("%d\n", b);
printf("%d\n", a);
return 0;
}
Output: $ cc -std=c99 -Wall -Wextra -pedantic foo.c && ./a.out
2
42
84
42
|