I have a simple objective c object
NSManagedObjectContext * moc = nil
Now I need to pass it into a function in an ARC environment that accepts parameter of type
void *volatile * value
I tried
&((__bridge void *)moc))
but I get the following compiler error
Address expression must be lvalue or a function pointer
I also tried
void ** addr = (__bridge void **)(&moc);
But I get the error
Incompatible types casting 'NSManagedObjectContext * __strong *' to 'void **' with a __bridge cast
Is there any way to first cast and then get the address of the casted pointer?
EDIT
To be more specific, I'm trying to implement the singleton pattern described in another stackoverflow question, but I'm having trouble feeding the address of the objective c NSManagedObjectContext
object into the third argument of the following function in an ARC environment.
OSAtomicCompareAndSwapPtrBarrier(void *__oldValue, void *__newValue, void *volatile *__theValue)