grahamr (03/30/83)
Cdecl translates things like declare fpa as array of pointer to function returning pointer to char into char *(*fpa[])() and vice versa. UNARY MUL is not a primary operator, but it does appear in C declarations. Cdecl helps mere humans deal with the precedence and associativity confusion that results. The source (and manual page) for cdecl appears on net.sources. Cheers. Graham Ross Design Automation Division Tektronix, Inc. (ucbvax|decvax)!tektronix!tekmdp!grahamr
kdmoen (03/31/83)
C declaration syntax ought not to be so confusing that a program
like 'Cdecl' is necessary. The biggest stumbling block in decoding
C declarations is the fact that the primary operators are postfix,
but unary * is prefix. I submit that the indirection operator (unary *)
should be postfix, not prefix. We would also have to use a different
symbol, since 'p* = x' would be confused with 'p *= x'. I propose '@'.
In other words, I would like 'p@' to mean '*p'.
The declaration
declare fpa as array of pointer to function returning pointer to char
would be written
char fpa[]@()@;
This may look just as cryptic as 'char *(*fpa[])();', but it doesn't
contain parentheses, and may be decoded fairly easily reading left to right:
char fpa declare fpa as
[] an array of
@ pointer to
() function returning
@ pointer to
char
Expressions containing large numbers of * . [] () operators will obtain
a similar boost in readability. As a special case, '(*p).tag'
will become 'p@.tag', and thus we no longer need a -> operator.
Note that the '@' operator can be added to the C language without
removing unary '*', so that existing C programs could still be compiled.
Instead, unary '*' could be phased out gradually, as is the =+ operator.
Thanks to Hugh Redelmeier for originally suggesting the idea.
Doug Moen, {allegra,decvax,utcsrgv}!watmath!kdmoensilver (04/04/83)
I agree; I've always thought the two biggest problems with C are (a) the lack of a WITH statement, and (b) the prefix (as opposed to postfix) operator for dereferencing a language. Watch out, though; I know of at least one implementation (derived from Modcal) where "^" is used for relative (i.e., normal) pointers and "@" is reserved for absolute-address pointers.
stuart (04/05/83)
I am reminded of Pascal's "^" notation. ... X := pointer^.field ...
thomas (04/10/83)
Nice idea (the @ syntax for pointers), but you didn't take it quite far
enough. Your example was
char fpa[]@()@;
char fpa declare fpa as
[] an array of
@ pointer to
() function returning
@ pointer to
char
This should obviously be
fpa[]@()@ char;
since otherwise you have to remember the "char" until the end.
=Spencer :=)