RE: Is pointer syntax logical?
RE: Is pointer syntax logical?
- Subject: RE: Is pointer syntax logical?
- From: Jeff Laing <email@hidden>
- Date: Fri, 27 Jul 2007 08:53:30 +1000
> You bring up a good point, but it's an issue of using an operator
> (and worse, the same operator as dereference) as a declaration
> modifier instead of a reserved word. Not really sure why they did it
> that way, but think about it like this:
You need to look back at where C came from. Bell Labs clearly hated typing.
Named the file creation function 'creat()' to save one extra byte.
All this talk about how confusing 'int *ip' is misses the point that the
language needs to be able to represent 'pointer to a memory location which
holds a pointer to a function (taking two pointer arguments) that returns a
pointer to a buffer of integers'. Or to put it another way, the address of
the interrupt vector which contains the callback routine to process address
errors. One level of indirection is trivial and tends to make the
requirements seem way simpler than they are.
The standard C argument says "You can tell how to INVOKE a complex pointer
expression by looking at its definition" - just remove the '*' from exactly
the same place that you put them in the deferencing expression and you have
the type of the resulting expression. Having to mentally translate from '*'
in one place to 'pointer' in the other.
Now, if they'd actually had the prescience to define 'typedef' right from
the start, the arguments might be different.
OB-Cocoa question: Does anyone else use typedef to mask out the clumsyness
of protocol syntax? ie, instead of:
@protocol foo
@end
...
id<foo> bar;
I've been doing
@protocol foo
@end
typedef id<foo> Foo;
...
Foo *bar;
Looks a lot more natural to me, but I'm not sure whether I'm setting myself
up for a fall...
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden