Re: va_list and unanticipated format specifiers
Re: va_list and unanticipated format specifiers
- Subject: Re: va_list and unanticipated format specifiers
- From: "email@hidden" <email@hidden>
- Date: Fri, 4 Jun 2010 22:35:59 +0100
On 4 Jun 2010, at 22:22, Ken Thomases wrote:
>
> The compiler will actually find this for you. Enabling -Wformat (which is included in -Wall) issues warnings for functions and methods that take format strings if you supply a non-literal format argument and no arguments. If you supply a literal format string, then the compiler checks the format specifiers in it against the types of the arguments you pass. If there's a mismatch in number or type, it warns for that, too.
>
Hmm. My current other warning flags currently are.
-Wextra -Wfloat-equal -Wall
The build current raises no warnings.
Anyhow -Wformat is in there now too.
> The current SDKs decorate such functions and methods in Cocoa with the attribute marking them as such. (The compiler automatically knows about C library functions, like printf.)
Ahh .. the sweet balm of knowledge.
FOUNDATION_EXPORT void NSLog(NSString *format, ...) NS_FORMAT_FUNCTION(1,2);
// Marks APIs which format strings by taking a format string and optional varargs as arguments
#if !defined(NS_FORMAT_FUNCTION)
#if (__GNUC__*10+__GNUC_MINOR__ >= 42) && (TARGET_OS_MAC || TARGET_OS_EMBEDDED)
#define NS_FORMAT_FUNCTION(F,A) __attribute__((format(__NSString__, F, A)))
#else
#define NS_FORMAT_FUNCTION(F,A)
#endif
#endif
Many thanks
Jonathan_______________________________________________
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