Rod Pemberton said:
I agree.
But, if it weren't for typedef's, we'd still have a default type of implicit
ints, because they don't create any serious language issues without
typedef's.
Also, if we want to completely eliminate ambiguity in the grammar (true
LALR(1)) we need two more tokens. One for an explicitly terminated if and
another for the use of a typedef as a type qualifier since we can't use
'typedef' itself (i.e., typedefname).
As I said to Torek (using an example of his), it's very easy to fix the
grammar:
#define typedefname ut
typedef int x;
int *a;
ut x *b; /* typedefname x *b */
int **p = &b;
void f(x); /* int x */
void f(ut x); /* typedefname x */
It's even portable:
#define ut
(Why "ut"?)
Yes, I suppose requiring "typedefname foo" rather than just "foo"
would probably solve the syntax problem -- though it would largely
defeat some of the purpose of having typedefs in the first place. At
least nobody would bother with:
typedef struct foo { ... } foo;
if it only meant being to refer to the type as either "struct foo" or
"typedefname foo".
It was my understanding (?), that implicit int's were removed to help solve
the ambiguities of a determining an implicit int versus a typedef.
C++ "GETTING RID OF DEFAULT INT" 3)b) :
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/1993/N0358.asc
It's always been my assumption that implicit int was removed just
because it's ugly (my word, not the committee's). The web page you
cited (which, BTW, discusses C++ not C, but the issues are very
similar) gives 4 major reasons for getting rid of implicit int. Two
of them have nothing to do with parsing issues, and IMHO those are the
strongest reasons.
From what I'm able to locate, it appears that typedef's were added after
implicit int's.
C in 1977 or so, typedef's added:
http://www.darwinsys.com/history/hist.html
C in 1974-5 has implicit int's, but no typedef's ("13. Implicit
declarations"):
http://cm.bell-labs.com/cm/cs/who/dmr/cman.pdf
http://cm.bell-labs.com/cm/cs/who/dmr/cman74.pdf
Right, so C has had implicit int since time immemorial, and typedef
since 1977 or so. It survived from 1977 to 1999 with both typedef and
implicit int. And removing implicit int has not, as far as I can
tell, completely solved the typedef problem. For example,
"sizeof(foo)" goes through a different grammatical production
depending on whether "foo" is currently a typedef name or not. (I'm
too lazy to come up with a better example right not.)