C's syntax (was Re: Python Formatted C Converter (PfCC))

Rainer Deyke root at rainerdeyke.com
Mon Oct 23 16:40:19 EDT 2000


"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:8t0or303ee at news1.newsguy.com...
>     foo * bar;
>
> if foo has been typedef'd (and thus is now a typename), this
> declares variable bar as a pointer-to-foo.  If foo has not been
> typedef'd, this has a completely different meaning, "evaluate
> this multiplication and throw the result away".

Actually, it means nothing at all unless foo is either a variable or a
typedef.  If you read 'foo * bar;', you must know the type of 'foo' to
understand it.  Think of it this way: operator '*' is overloaded for typdefs
to create a variable instead of multiplying.  And you can't use it wherever
you can use an expression, but can use in places where expressions are
illegal.  On second thought, don't think of it like that.

> Even from a human-factors point of view, such syntactic
> tripwires (over which people DO keep stumbling...) as
>     if(a=0) ...       /* oops, an assignment...! */
> or
>     foo* bar, baz;    /* NOT two pointers... */

It gets worse.

int (*a)[5], *(b[5]);

It looks like 'a' is an array of pointers and 'b' is a pointer to an array,
but the opposite is the case.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list