A bit of history may clarify the horrible typedef syntax: the earliest
C compilers (early 1970s) didn't have the typedef keyword. Repeating
the often complicating struct definitions or function prototypes all
over the place was a mess so they came up with a quick hack: the
typedef keyword acted as a storage class specifier, e. g.
-
static int t;
-
...
-
typedef int t;
-
Instead of defining an identifier t with a type int with a storage
class 'static' another name was defined which serves as an
alternative for the type int; (see the example). The hack caused
quite a complication for the lexical analyzer though because after
it scanned 't' it didn't know what to return to the parser: a type
or an identifier? (compare this after the lex-analyzer had seen
'int'; it would've known to tell the parse what it had just seen).
The scanner would simply return the token 'type-or-ident' and
leave the decision to the parser. The decision became a context
sensitive decision; see the next example:
-
typedef int t;
-
t t(t t) { ... }
-
Try to figure out what each 't' means in that text. Many wrong
implementations existed in those day until the Standards
attempted to straighten things out a bit. No matter what, the
typedef feature remains an ugly little hack.
kind regards,
Jos