Re: Newbie question about _NSSize and NSSize
Re: Newbie question about _NSSize and NSSize
- Subject: Re: Newbie question about _NSSize and NSSize
- From: Alastair Houghton <email@hidden>
- Date: Mon, 27 Aug 2007 22:54:38 +0100
On 27 Aug 2007, at 12:43, Frank Bettger wrote:
In Hillegass book there is a challenge in chapter 5. It says
The second argument is a C struct that contains the size that the
user has
asked for:
typedef struct _NSSize {
float width;
float height;
} NSSize;
If I understand the construction above NSSize is just another name for
_NSSize. My question is what's the purpose of giving two nearly
identical
names for a structure?
I'm not sure anyone's mentioned this yet (so I will).
The thing between "struct" or "enum" and the open brace is called a
"tag". In vanilla C, it exists in a separate namespace to ordinary
type names and other symbols.
As for why this is useful, many C programmers used to use it to
distinguish between types you could poke around in, and types you
shouldn't. Generally speaking, those that you are allowed to access
the members of were declared without using typedef, and those whose
members were notionally private were typedef'd. This practice has
largely, but not completely died out, presumably because people are
(often badly) trained in C++ rather than C, where struct tags are in
the same namespace as other types.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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