Using sizeof Correctly with Byte[]

后端 未结 3 1259
感情败类
感情败类 2021-01-15 17:06

I\'m sort of out of my depths here, but I have the following code (the real code actually has a point of course):

- (NSData*) dataTheseBytes:(Byte[]) bytes {         


        
3条回答
  •  粉色の甜心
    2021-01-15 17:21

    When you pass a C array as a method or C function argument, it "decays" to a pointer to the underlying type (i.e. Byte[] is actually passed as Byte *.) So the called method/function has no idea how many elements are present in the array.

    You must also pass the length of the array in order for the called code to know what you want. That's why +[NSData dataWithBytes:length:] has that second argument.

提交回复
热议问题