您的位置:首页 > 移动开发 > Objective-C

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
static void * ptr = &ptr
in 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 :)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: