Re: "Format not a string literal and no format arguments"
Re: "Format not a string literal and no format arguments"
- Subject: Re: "Format not a string literal and no format arguments"
- From: Ken Thomases <email@hidden>
- Date: Sat, 29 Aug 2009 14:31:06 -0500
On Aug 29, 2009, at 2:19 PM, Quincey Morris wrote:
On Aug 29, 2009, at 11:54, Peter Duniho wrote:
Or is it implied that the compiler is doing compile-time
verification of the format string when a literal is provided?
Sort of, but not exactly.
Actually, yes exactly.
So if you provide a string literal, there's no warning because it's
assumed you're not going to hard-code stray '%' characters in it.
No such thing is assumed. If you provide a string literal, the
compiler actual checks it and the arguments to make sure they're
consistent with each other.
$ cat foo.c
#include <stdio.h>
int main(void)
{
printf("%d\n", "blah");
return 0;
}
$ cc -Wall -o foo foo.c
foo.c: In function ‘main’:
foo.c:4: warning: format ‘%d’ expects type ‘int’, but argument
2 has type ‘char *’
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden