"f" after number

typeoneerror picture typeoneerror · Mar 6, 2010 · Viewed 65k times · Source

What does the f after the numbers indicate? Is this from C or Objective-C? Is there any difference in not adding this to a constant number?

CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 50.0f);

Can you explain why I wouldn't just write:

CGRect frame = CGRectMake(0, 0, 320, 50);

Answer

Frank Shearar picture Frank Shearar · Mar 6, 2010
CGRect frame = CGRectMake(0.0f, 0.0f, 320.0f, 50.0f);

uses float constants. (The constant 0.0 usually declares a double in Objective-C; putting an f on the end - 0.0f - declares the constant as a (32-bit) float.)

CGRect frame = CGRectMake(0, 0, 320, 50);

uses ints which will be automatically converted to floats.

In this case, there's no (practical) difference between the two.