Re: [OT] A bit confused on pointers...
Re: [OT] A bit confused on pointers...
- Subject: Re: [OT] A bit confused on pointers...
- From: Camillo Lugaresi <email@hidden>
- Date: Fri, 30 Dec 2005 11:45:57 +0100
On 30/dic/05, at 11:10, Andreas Mayer wrote:
Am 29.12.2005 um 21:39 Uhr schrieb Clark Cox:
what is confusing about the syntax?
If (ptr) is a pointer, then (*ptr) is whatever it points at
Umm... what's *not* confusing about that syntax?
* is usually associated with multiplication.
And as Pontus pointed out, it doesn't help that the same symbol is
used in the declaration of pointers. To make things worse, it's
customary to write int *ptr instead of int* ptr, which would
be more accurate in my opinion. The '*' modifies the type, after
all, not the identifier.
Wrong!
int *a, b;
What type is b? int. If you want two pointers to int, write:
int *a, *b;
It's also useful when declaring types:
typedef struct {
int x;
int y;
} Point, *PointPtr;
Then there is the & operator, which is often used in conjunction
with pointers; and of course, this character does have a different
meaning when used as a binary operator.
But there's never any ambiguity about whether the operator is unary
or binary in an expression.
To make things worse, there's also &&.
It would be so much more readable if pointers where just declared
as int pointer myPointer and dereferenced like deref
(myPointer) or something like that.
It would be more readable to someone who only rarely uses pointers,
and thus can't remember the notation. But if you use pointers all the
time, as is typical in C programs, such a verbose syntax would be
really cumbersome. There's a reason if not even Pascal went that
far. :-)
Actually I don't like the C declaration syntax anyway. There should
be a special character clearly separating the type from the
identifier.
int pointer: myPointer;
But this is all really off topic and C will not change, no matter
how much we discuss it.
Agreed. But I'll leave you with a suggestion: have a look at the
syntax for references in Perl. I think you might find a new
appreciation for the clarity of C syntax. ;-)
Camillo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden