Possible Duplicate:
objc warning: “discard qualifiers from pointer target type”
I'm having a bit of trouble converting an NSString
to a C string.
const char *input_image = [[[NSBundle mainBundle] pathForResource:@"iphone" ofType:@"png"] UTF8String];
const char *output_image = [[[NSBundle mainBundle] pathForResource:@"iphone_resized" ofType:@"png"] UTF8String];
const char *argv[] = { "convert", input_image, "-resize", "100x100", output_image, NULL };
// ConvertImageCommand(ImageInfo *, int, char **, char **, MagickExceptionInfo *);
// I get a warning: Passing argument 3 'ConvertImageCommand' from incompatible pointer type.
ConvertImageCommand(AcquireImageInfo(), 2, argv, NULL, AcquireExceptionInfo());
Also when I debug argv
it doesn't seem right. I see values like:
argv[0] contains 99 'c' // Shouldn't this be "convert"?
argv[1] contains 0 '\100' // and shouldn't this be the "input_image" string?
The warning is because you are passing a
char const **
(pointer-to-pointer-to-const-char) where the API expects achar **
(pointer-to-pointer-to-char, in particular a NULL-terminated list of non-const C strings).My point being the
const
makes the pointer types incompatible. The safe way to get around that is to copy the UTF8 strings into non-const C-string buffers; the unsafe way is to cast.Richard is correct, here is an example using
strdup
to suppress the warnings.Use cStringUsingEncoding or getCString:maxLength:encoding: