C type declarations

jrv at Mitre-Bedford jrv at Mitre-Bedford
Sun Jan 13 10:36:02 AEST 1985


I (think I) understand the C types involving the operators *,
(), and [], but I find the C syntax confusing. Judging from
recent discussions on multidimensional arrays and functions
returning pointers, I'm not alone.  I'd like to bring up a
suggestion I ran across several years ago: to replace the
prefix operator * with the postfix operator ^.  The three
operators ^, (), and [] can have the same precedence, and are
executed from left to right. The declaration syntax is also
changed to put the basic type last, so that a declaration can
be read from left to right...
        var a()^[]^ : int;
declares a to be a FUNCTION returning a POINTER to an ARRAY
of POINTERS to INTEGERS. The colon can move without changing
the meaning, as in
        var a()^[] : ^int;
but the colon is useful so that several related objects can
be declared at once, so
       var a()^[],b(),c[3] : ^int;
declares a as above, b to be a FUNCTION returning a POINTER to
an INTEGER, and c to be an ARRAY of three POINTERS to INTEGERS.

I've always liked the idea. I realize it's unlikely to be
added to C at this late date, but I could hope to see it in
a preprocessor or a new language.

(By the way, I thought I saw this in SIGPLAN Notices several
years ago, but I looked through all my back issues and can't
find it.  Can anyone else supply the reference?)

                - Jim Van Zandt



More information about the Comp.lang.c mailing list