Lies in education [was Re: The "loop and a half"]

Gregory Ewing greg.ewing at canterbury.ac.nz
Wed Oct 11 17:55:36 EDT 2017


bartc wrote:
> While on the subject of C syntax, here are some fun ambiguities:
> 
> f(x);    // call function with arg x, or declare x of type f?
> 
> a*b;     // multiply a by b, or declare b of type pointer to a?
> 
> (a)*b    // multiply a by b, or cast *b to type a?

Technically these are not ambiguous in C, because the context always
makes it clear whether you're dealing with a declaration or an expression.
The indications can be subtle sometimes, but they're there.

In C++ they really are ambiguous in some cases, and some arbitrary
rules had to be added to disambiguate them. (I think the rule is
"if it could be a declaration, then it is" or something like that.)

-- 
Greg



More information about the Python-list mailing list