开发者

How to use Array of C language with Objective-C

I'm using Objective-C language. But I don't know how to use c with Objective-C.

Ex) This is Function method.

- ( ?? ) function{
unsigned int first = ..
unsigned int second = ..
unsigned int t开发者_高级运维hird = ..

int infoData = {first,second,third};
return infoData;
}

How to fill in parenthesis.

I don't use NSArray.

Please help me.


the answer is the same as it is in C. Objective-C is a strict superset of C.


Assuming you declared int[] infoData you could make the return int*, but you're still going to have problems because the array is allocated on the function's stack. You'll need to dynamically allocate space for it just like you would in C.

(You cannot use int[] as a return type)

The code below will compile, but gcc will warn about returning the address of a function local variable.

@interface test
- (int*) function;
@end

@implementation test

- (int*) function{
  unsigned int first = 0;
  unsigned int second = 1;
  unsigned int third = 2;

  int infoData[] = {first,second,third};
  return infoData;
}

@end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜