Quantcast
Channel: What do people mean when they say C++ has "undecidable grammar"? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Answer by Thomas L Holaday for What do people mean when they say C++ has "undecidable grammar"?

$
0
0

If "some people" includes Yossi Kreinin, then based on what he writes here ...

Consider this example:

x * y(z);

in two different contexts:

int main() {    int x, y(int), z;    x * y(z);}

and

int main() {    struct x { x(int) {} } *z;    x * y(z);}

... he means "You cannot decide by looking at x * y(z) whether it is an expression or a declaration." In the first case, it means "call function y with argument z, then invoke operator*(int, int) with x and the return value of the function call, and finally discard the result." In the second case, it means "y is a pointer to a struct x, initialized to point to the same (garbage & time-bomb) address as does z."

Say you had a fit of COBOLmania and added DECLARE to the language. Then the second would become

int main() {    DECLARE struct x { x(int) {} } *z;    DECLARE x * y(z);}

and the decidability would appear. Note that being decidable does not make the pointer-to-garbage problem go away.


Viewing all articles
Browse latest Browse all 6

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>