• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: "Format not a string literal and no format arguments"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: "Format not a string literal and no format arguments"
      • From: Quincey Morris <email@hidden>
References: 
 >"Format not a string literal and no format arguments" (From: Jonathan del Strother <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Quincey Morris <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Peter Duniho <email@hidden>)
 >Re: "Format not a string literal and no format arguments" (From: Quincey Morris <email@hidden>)

  • Prev by Date: Testing localizations in 10.6
  • Next by Date: Re: Testing localizations in 10.6
  • Previous by thread: Re: "Format not a string literal and no format arguments"
  • Next by thread: Re: "Format not a string literal and no format arguments"
  • Index(es):
    • Date
    • Thread