Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call Static Method with C Syntax in Obj-C?

I could redo this method using proper Obj-C syntax, but I was wondering how to call this from Obj-C. The method looks like this

@interface YarMidiCommon : NSObject

static
MIDIPacketList *makePacketList(Byte *packetBuffer, const UInt8 *data, UInt32 size);

@end

but I have no idea how to call that method. I have tried

Byte packetBuffer[size+100];
MIDIPacketList *packetList = makePacketList(packetBuffer, bytes, size);

but the error is "has internal linkage but is not defined." Is this possible without resorting to "proper" Obj-C syntax?

For the record, the method that I want to emulate would be something like

+ (MIDIPacketList*) makePacketListWithPacketBuffer:(Byte*)packetBuffer data:(const UInt8 *)data size:(UInt32)size;

which is verbose and annoying, seeing as everything here is C anyway.

This is related to this other answer I got today.

like image 862
Dan Rosenstark Avatar asked Dec 12 '22 06:12

Dan Rosenstark


1 Answers

Since the function is a C function you need to remove the static keyword or else it will not be visible outside of its translation unit. Once you do that the first example you have will work. Also since it is a C function placing its declaration inside or outside of the @interface and definition inside or outside of the @implementation makes no difference on how you will call it.

like image 191
Joe Avatar answered Dec 30 '22 07:12

Joe