문제

Quick question on NSLog and printf:

I am running the following in Xcode:

char array[10] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
char *arrayPtr = array;

NSLog(@"TEST:  %c", *(arrayPtr+9));

printf(@"TEST:  %c", *(arrayPtr+9));

Every line works fine except this:

printf(@"TEST:  %c", *(arrayPtr+9));

Error:

Implicit conversion of an Objective-C pointer to 'const char *' is disallowed with ARC.

Could you explain to me what happens here and if a simple cast here would make it work?

NSLog works ok, no error whatsoever. But printf does. I have tried using __bridge cast, but it doesn't seem to satisfy it.

Is there a way to make this work without needing to turn off ARC?

도움이 되었습니까?

해결책

The error has nothing to do with the char array or arithmetic. It's telling you that you're passing an NSString to printf() as the format string, when you need to pass a regular C string:

printf("TEST:  %c", *(arrayPtr+9));
//     ^ No @
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top