不能将本地数组分配给要在当前堆栈帧之后保留的指针。你必须使用动态记忆,从
malloc()
或者类似的功能。如果你想使用字节数组,你必须
malloc()
memcpy()
和
free()
每次要重新分配内存时,都会正确地分配内存。
- (IBAction) checkNow {
NSLog(@"now? %d %d %d", theBytes[0], theBytes[1], theBytes[2]);
}
- (void)viewDidLoad {
[super viewDidLoad];
uint tryThis[3] = {72,2,244};
theBytes = malloc(3 * sizeof(uint));
memcpy(theBytes, tryThis, 3 * sizeof(uint));
[self checkNow];
}
// In order not to leak, you'll also need:
- (void)dealloc {
free(theBytes);
[super dealloc];
}