What does it mean to write `static void * ptr = &ptr` in objective-c?
2015-07-10 16:33
726 查看
What does it mean to write
问题:
i am reading apple’s recently (dec 5, 2013) updated sample code for camera control using av foundation (here is the link). and i come across the following lines in the file avcamviewcontroller.m which i don’t understand.
回答:
static void * ptr = &ptrin objective-c?
问题:
i am reading apple’s recently (dec 5, 2013) updated sample code for camera control using av foundation (here is the link). and i come across the following lines in the file avcamviewcontroller.m which i don’t understand.
static void * capturingstillimagecontext = &capturingstillimagecontext;static void * recordingcontext = &recordingcontext;static void * sessionrunninganddeviceauthorizedcontext = &sessionrunninganddeviceauthorizedcontext;
回答:
well, so idea for these constants is to have some unique value, that will not repeat anywhere in the program, but we don't really care about its content. now, instead of coming up with some random string/number etc, we just create a pointer, and put its address as content, this way it's unique and the code is simple is nice :)
相关文章推荐
- [Objective-C] Cocoa's Target-Action Pattern
- iwebshop (: Cannot use object of type stdClass as array in)
- Scripting.FileSystemObject对象
- Objective-C语法之动态类型
- The method fromObject(String) is undefined for the type JSONObject
- id ,NSObject和id<object>的区别
- IOS基础:IOS及ObjectC基础知识
- [Objective-C] Protocol 简介
- Objective-C知识整理——实例变量修饰符
- function invoke objects DEMO
- [Objective-C] strong/weak 属性——狗项圈的比喻
- GitHub 上排名前 100 的 Objective-C 项目简介
- interweaving of objects DEMO
- 黑马程序员 面向对象 多态 需求 object
- [Objective-C] self 和 this 的区别
- Java 兑换ObjectC代码
- ObjectStreamDemo
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第十七章 内存管理和自动计数
- 编写高质量的Objective-C代码(转)
- Objective-C(十八、谓语使用及实例说明)——iOS开发基础