Quantcast
Channel: User CPlus - Programming Language Design and Implementation Stack Exchange
Viewing all articles
Browse latest Browse all 66

Why are mixed declarations more challenging to implement than forcing all declarations to be at the top of a scope?

$
0
0

C89 had a requirement that all declarations must appear at the top of the scope before any statements:

int func(void) {    int x = 10;    f();    int y = 20; // Invalid    // ...}

However this requirement was easy to get around most of the time, either by simply moving declarations to the top, and initializing them out of line if their initializer expressions were order-sensitive to the code in the statements, or one could just put a scope around them:

int func(void) {    int x = 10;    f();    {        int y = 20; // Valid        // ...    }}

Given that the C99 requirement to allow mixed declarations did not cause any problems (that I am aware of, as in this could not have possibly broken legacy code, etc.) and that identical semantics could be easily achieved by using the {} hack above, what prevented old C89 compilers from handling mixed declarations?


Viewing all articles
Browse latest Browse all 66

Trending Articles