Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does it mean to write `static void * ptr = &ptr` in Objective-C

Tags:

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;

What does it mean to assign the pointer of itself? Why do we need this?

Update (2015-10-02): Now the AVCam is updated and rename to AVCam-iOS, if you are still insterest in this code AVCamViewController.m.

like image 536
Yuchen Avatar asked Dec 16 '22 03:12

Yuchen


1 Answers

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

like image 193
Dmitry Shevchenko Avatar answered Dec 17 '22 16:12

Dmitry Shevchenko