jacob navia said:
Yes, did you know?
int (*export)(int a,char *name);
is illegal C++.
It is a pity that C++ did not develop positional keywords. In my
extensions to C, I always use positional keywords, i.e. keywords that
would be otherwise a syntax error. Otherwise, they are not recognized
as keywords.
Using lcc-win you can still write
int operator = 5;
the "operator" keyword is recognized only in the prefix of a function
definition.
It would be much easier for all if C++ would follow that convention
but I suppose it is too late now.
I both like and dislike the idea of positional keywords.
In a language that will never change, it's much cleaner IMHO just to
have reserved keywords. Not being able to use "if" or "return" as an
identifier is a small price to pay for the conceptual simplicity of
knowing whether an identifier-like thing is a keyword or not just by
seeing how it's spelled.
The problem is that languages evolve. C99 added several new keywords
that weren't in C90, breaking all existing C90 programs that used
"inline" or "restrict" as ordinary identifiers. On the other hand,
some of the new keywords were added in a form that wouldn't break
existing code, such as _Bool and _Complex -- but of course if those
had been in the language from the beginning, surely "bool" and
"complex" would have been keywords. If I'm programming in C99
(ignoring for the moment the relative lack of support), I shouldn't
have to care when a given keyword was introduced into the language.
Positional keywords require some extra work for the compiler to
recognize whether a given occurrence of, say, "operator" is a keyword
or an identifier. I'm not too concerned about the compiler having to
do extra work, but if the compiler has to work harder to understand
something, the human reader likely will as well.
Ideally, languages should be designed from the start to allow for
future expansion. One approach, I suppose, is not to reserve any
keywords at all. This requires constructing the grammar in such a way
that you can always tell whether a given word is being used as a
keyword for not. This means, for example, that a return statement
can't be allowed to resemble a function call; given:
return (result);
the compiler couldn't tell whether "return" is a function name or the
keyword. (Resolving this based on whether there's a visible function
by that name would cause too many problems.)
Another approach is to use a different syntax for keywords
vs. identifiers. I think Algol did this, though the language itself
didn't define how they were differentiated. You might have a leading
or trailing underscore on each keyword, or require each keyword to
start with an uppercase letter; either way, you'd disallow that form
for identifiers.
Or you can just use a limited set of reserved keywords and make sure
you define the perfect language from the beginning.