0

I do have an objective-c object myObject. Inside this object I do have some C-functions.

static void C_doThing(void) { ... }

Inside myObject i can just call C_doThing() and the function gets called. Now I want to call a method of myObject from this C-function.

Is there a way to do this? "Self" is not available inside the C-function.

Thanks

DenTek
  • 37
  • 2
  • 1
    Au contraire, you do not have C functions inside your object. They're simply in the same compilation unit. – Hot Licks Sep 18 '14 at 19:58

1 Answers1

0

No; the C function is just a plain C function that happens to be defined inside your .m file, but it's not actually "part" of the object (class). It just happens to be stuck sitting there in the same file.

You could pass the object (self in the caller) in as an argument to the function, and then call methods on it.

But you should probably just make it into a normal instance method. You've defined it as static, which means it has no visibility outside of the file. If that's the case, then why not make it a method?

(There may be a small number of good cases for using utility C functions that are used only within a single class implementation, but they're pretty rare and typically around serious performance optimization.)

Ben Zotto
  • 70,108
  • 23
  • 141
  • 204