-1

Can someone explain the following code to me? I'm confused on the return values and the meaning of "static inline".

static inline CGFloat skRandf()
{
    return rand() / (CGFloat) RAND_MAX;
}

static inline CGFloat skRand(CGFloat low, CGfloat high)
{
    return skRandf() * (high - low) + low;
}
Whirlwind
  • 14,286
  • 11
  • 68
  • 157
Sergio
  • 33
  • 1
  • 4

1 Answers1

2

Both functions return a type of CGFloat, which is a platform-dependent type that holds either a 32-bit or 64-bit floating point number.

static is a C keyword that ensures the function in question isn't visible to other translation units. In many cases, this means that code outside the source file in which the static function was defined cannot invoke the function. See this question for more details about exactly how static works in C.

inline is a C keyword that suggests to (but not requires that) the compiler that the function should be compiled inline; e.g. instead of making a call the body of the function is substituted in at the call site. This Wikipedia article goes into what inline does in more detail.

Community
  • 1
  • 1
AustinZ
  • 1,787
  • 1
  • 13
  • 21