Do NSDouble, NSFloat, or other types than NSInteger exist?

后端 未结 3 1461
北海茫月
北海茫月 2020-12-29 19:46

Over at In Cocoa do you prefer NSInteger or just regular int, and why?, there was mention of NSDouble and NSFloat, but I can\'t see a reference for

3条回答
  •  -上瘾入骨i
    2020-12-29 20:15

    It's also about conventions.

    A typedef to an int is incompatible to int int itself.

    Example: pid_t is of type int, but passing an int would create a warning.

    Why? Because you want to be sure that if you cross API boundaries everyone knows what the code expects.

    There are float and double types, i.e NSTimeInterval. It's not really about the underlying type, but the convention to adhere to.

    If you declare a local int as a loop counter and you do not plan to pass it to a well-defined API, it's fine to call an int an int.

提交回复
热议问题