Different treatment of %d in ObjectiveC versus iOS
1st question here. R开发者_JAVA百科eviewed FAQ but did not find answer.
I learned Obj C using Kochan book and he classifies %i for integers, %f for float, %d for double.
Using iOS, it seems that it is rather: %i and %d for integer and %f for float
Can someone confirm and maybe explain the rationale. I already looked through the string programming guide of Apple.
Thank you in advance.
The standard C/C++ syntax is followed. So %d and %i are both 'signed integer', %f is 'decimal floating point' and will show floats or doubles.
Without being sure why d and i are duplicated, the reason that %f does floats and doubles is that things passed via an ellipsis are subject to the C promotion rules. If you pass any integer type that is smaller than an int, it'll be promoted to a full size int for passing. Similarly, if you pass a float, it'll be promoted to a double. So the thing receiving the arguments just needs to think in terms of integer versus floating point, not about storage size.
精彩评论