Re: [OT] A bit confused on pointers...
Re: [OT] A bit confused on pointers...
- Subject: Re: [OT] A bit confused on pointers...
- From: Alastair Houghton <email@hidden>
- Date: Fri, 30 Dec 2005 15:14:47 +0000
On 30 Dec 2005, at 14:01, Steve Bird wrote:
On Dec 30, 2005, at 5:10 AM, Andreas Mayer wrote:
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.
Coming from Pascal (where you are forced to write var p: ^integer),
this made perfect sense to me, UNTIL I discovered that it doesn't
work the way I thought it would.
In Pascal, var p1,p2: ^integer declares TWO pointers to integers,
but in C, int* p1, p2 does NOT. As much as it makes sense to read
it that way, the compiler sees it otherwise.
The way C interprets it makes perfect sense also; '*' is a unary
right-associative operator, wherever it appears in the code. Same
for '&' in C++. i.e. if you write "int* a" (or in C++ "int& a"), you
are deluding yourself... the compiler will never read things that way
around, no matter how much whitespace you insert.
Anyway, I think this has probably been done to death now, and since
it's really basic C stuff, it'd be a good idea for anyone who is
still confused to find themselves a good book on C. I recommend
avoiding the plethora of brightly-coloured books on C++ and just
finding something that concentrates on C; the C++ books often spend a
lot of time on the new features of C++ at the expense of more
coverage of the basics of the underlying C language.
The FAQ document I wrote some time ago lists a few books that have
been recommended in the past; see <
http://www.alastairs-place.net/
cocoa/faq.txt>. It needs a bit of updating (perhaps I'll get some
time to do this soon... we'll see).
More experienced programmers might like to get a copy of the ANSI C
spec itself (Wiley do a nice printed version, ISBN 0-470-84573-2; the
C++ spec. is also available under ISBN 0-470-84674-7).
Kind regards,
Alastair.
--
http://www.alastairs-place.net
_______________________________________________
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