CompuServe Messages

languages

    12-Feb-92 13:29:10
Sb: #20271-languages
Fm: Greg Comeau@Comeau Cmptg 72331,3421
To: Shraddhan 70374,754
>Is the compiler so clever that it can follow the logic of a program >well enough to actually do this? In enough cases: yes. First of all, all static variables become initialized implicitly if you do not do so explicitely. Automatics without initializers have undetermined values though. So, it becomes a quality of implementation issue that it should diagnose twice something like: void foo() { int i; int j; printf("%d\n", i); /* who know what prints out */ i = j; /* j used before set */ } There are queasy cases though that are either too much work, or sometime impossible to calculate. Consider: main() { int i; int j; scanf("%d", &i); if (i) j = i; /* j is either i here, OR who know what */ } Not that a compiler can't do flow analysis and conclude anything, but that case does before iff'y er since something like "j might not be set" starts getting inconclusive (unless addition info can be provided).