views:

36

answers:

2

Is there any real need to do this:

CGFloat x = 10.0f;
CGFloat y = 20.0f;

someView.center = CGPointMake(x, y);

Instead of this:

float x = 10.0;
float y = 20.0;

someView.center = CGPointMake(x, y);

...aside from style considerations?

Are there any performance implications at all?

+4  A: 

Usually those sorts of data types are used for readability, but also for portability. If the CoreGraphics library were to change it's implementation or data types the CGFloat type would help it better match the API. This can also be significant when considering portability across platforms.

I doubt there is any sort of performance difference - it will probably end up still being a float in the compiled code.

ghills
Well, the former code uses `float` literals for a type that may be `double`, whereas the latter code uses `double` literals for a type that may not be equivalent to `double`. A strictly-literal compiler would always include `float` literals in `float` format and `double` literals in `double` format, but a real compiler might store initializer values already converted to the variable's type, resulting in no performance difference when the variable is `CGFloat` and a tiny penalty when it's not (when you pass it to a function that requires `CGFloat` and the type doesn't match).
Peter Hosey
+4  A: 

See this answer for a good explanation of CGFloat. It is basically a typedef for code portability between 32-bit and 64-bit platforms.

Tim Isganitis