What does it mean to write `static void * ptr = &ptr` in objective-c?

转载 2015年07月10日 16:33:55

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 :)

"Batch,Batch,Batch":What does it really mean?

记录阅读Nvidia文章《"Batch,Batch,Batch":What does it really mean?》的一些心得

What does (Aborted) mean in HttpWatch?

What does (Aborted) mean in HttpWatch?The result column in HttpWatch may sometimes display the value...
  • jawiudi
  • jawiudi
  • 2011年05月06日 19:54
  • 712

How does @synchronized lock/unlock in Objective-C?

问题:Does @synchronized not use "lock" and "unlock" to achieve mutual exclusion? How does it dolock/un...
  • Koupoo
  • Koupoo
  • 2011年07月01日 08:57
  • 683

使用Objective-C的+(void)initialize初始化static变量

在《Objective C类方法load和initialize的区别》一文中,我介绍了Objective-C对待+(void)initialize和+(void)load两个方法在编译和执行时出现的不...

What is a meta-class in Objective-C?

In this post, I look at one of the stranger concepts in Objective-C — the meta-class. Every class in...

Objective-C categories in static library

转自:http://stackoverflow.com/questions/2567498/objective-c-categories-in-static-library 问: ...

how to use mp4box in objective-c

// //  ProcessingController.m //  VF-X264 // //  Created by John Paul Alcala on 10/30/10...
  • yuanya
  • yuanya
  • 2014年03月05日 10:09
  • 821

The elephant on the doorstep: What Wal-Mart’s arrival will mean to D.C.

The elephant on the doorstep: What Wal-Mart’s arrival will mean to D.C.By Jonathan O'Connell, Sunday...
  • anperl
  • anperl
  • 2011年04月12日 16:21
  • 477

What is reflection and how to use it in CSharp ?

What is reflection and how to use it in CSharp ?
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:What does it mean to write `static void * ptr = &ptr` in objective-c?
举报原因:
原因补充:

(最多只允许输入30个字)