Calling a static method with C syntax in Obj-C?

I could redo this method using the correct Obj-C syntax, but I was wondering what to call it from Obj-C. The method is as follows

@interface YarMidiCommon : NSObject static MIDIPacketList *makePacketList(Byte *packetBuffer, const UInt8 *data, UInt32 size); @end 

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

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

but the error "has an internal connection but is not defined." Is this possible without resorting to the β€œcorrect” Obj-C syntax?

For the record, the method I want to emulate will look like

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

which is verbose and annoying since everything here is C. anyway.

This is related to this other answer I received today.

+4
source share
3 answers

Since the function is a C function, you need to remove the static keyword, otherwise it will not be visible outside its translation unit. Once you do this, you will have the first example. In addition, since it is a C function that places its declaration inside or outside of @interface , and the definition inside or outside of @implementation has nothing to do with how you call it.

+8
source

Consider the declaration as equivalent to the static function C in the global domain. This is very different from C ++ or Java. There is no class or external link for this function.

Thus, the @interface area would not be a good place to declare makePacketList . A message means that the definition is not displayed when you use it.

+5
source

You need to move the function to .m (it makes sense if you use it only from this file) or remove the static .

+1
source

Source: https://habr.com/ru/post/1389555/


All Articles