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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to