0

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?

1 Answer 1

3

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 @
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.