Nik
Nik

Reputation: 9431

Send Objective-C message to C void *

Two questions:

  1. Is it possible to send objective-c message to C void * from C function?
  2. Is it possible to hint void * with <SomeProtocol> in C-function declaration? In function body?

(pseudocode)

// myfunc.h
void myfunc(void *object, int param);

// myfunc.c
void myfunc(void *object, int param) {
    // desired (pseudocode):
    // [<SomeProtocol>(id)object method:param];
}

// objective-c controller
# include "myfunc.h"
// ....
@implementation

- (void)visible_to_outer_world {
    Object *o = [Object new];
    myfunc(o, 5);
}

// ....
@end

Upvotes: 1

Views: 138

Answers (1)

user529758
user529758

Reputation:

Is it possible to send an Objective-C message to a void * from a C function?

Not sure why you would want it, but if you're compiling as Objective-C:

void bar(void *ptr)
{
    // MRC version:
    [(id)ptr someMessage];

    // ARC (alias "ugly") version:
    [(__bridge id)ptr someMessage];
}

Foo *foo = [[Foo alloc] init];
bar(foo);

Is it possible to hint void * with <SomeProtocol> in a C function declaration? In a function body?

No.

Upvotes: 5

Related Questions