Question

Here's some instance variables in a header file from an iphone game develpment book:

CGFloat *point;
int count;
CGFloat vectorScale;

Now I'm absolutaley confused. What's that asterisk before the point ivar? Is CGFLoat a class as well as it's not?

Was it helpful?

Solution

A CGFloat is just a C typedef for float or a double depending on your platform. On modern machines its probably a double. This means that *point as a pointer to a float. Given that name, its probably (educated guess) a pointer to an interleaved array of x y coordinates.

OTHER TIPS

it's not a class. on iOS, it is a float. on osx, it is float or double.

the asterisk says that point is a pointer to a CGFloat. an introductory C book will explain pointers.

If you want to know what one of these thing is in Xcode, option-click on the type. You will be taken to its actual definition. What I get is:

#if defined(__LP64__) && __LP64__
# define CGFLOAT_TYPE double
# define CGFLOAT_IS_DOUBLE 1
# define CGFLOAT_MIN DBL_MIN
# define CGFLOAT_MAX DBL_MAX
#else /* !defined(__LP64__) || !__LP64__ */
# define CGFLOAT_TYPE float
# define CGFLOAT_IS_DOUBLE 0
# define CGFLOAT_MIN FLT_MIN
# define CGFLOAT_MAX FLT_MAX
#endif /* !defined(__LP64__) || !__LP64__ */

typedef CGFLOAT_TYPE CGFloat;
#define CGFLOAT_DEFINED 1

tl:dr it's never a class :-)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top