Convert CFIndex to NSUInteger?

扶醉桌前 提交于 2019-12-11 02:04:50

问题


How do I convert typedef signed long CFIndex to typedef unsigned int NSUInteger?

Is it OK if I use a CFIndex as an argument of type NSUInteger. I haven't casted it, and the complier doesn't seem to mind. Does the compiler just do the conversion for me?


回答1:


You need to be very careful here, since CFIndex is signed and NSUInteger is unsigned. There are various routines that return a CFIndex -1. You need to check for that before using it as an NSUInteger.




回答2:


Yes, the compiler performs implicit type conversion.



来源:https://stackoverflow.com/questions/9952738/convert-cfindex-to-nsuinteger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!