C declaration tool

utzoo!watmath!kdmoen utzoo!watmath!kdmoen
Thu Mar 31 07:35:35 AEST 1983


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 at .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!kdmoen



More information about the Comp.lang.c mailing list