Re: [Somewhat-OT] Unexpected behaviour of variable argument lists
Re: [Somewhat-OT] Unexpected behaviour of variable argument lists
- Subject: Re: [Somewhat-OT] Unexpected behaviour of variable argument lists
- From: Ondra Cada <email@hidden>
- Date: Thu, 16 Sep 2004 17:54:42 +0200
J o a r,
On 16.9.2004, at 15:03, j o a r wrote:
Consider the following log statement with an incorrect, or at least
unusual, set of arguments:
int someIntegerValue = 3;
NSLog(@"A format string: %d" "Some other string", someIntegerValue);
I would have expected it to generate a compiler error
Nope. Presumed the important thing indeed is the forgotten comma, the
compiler does concatenate strings (and NSStrings, too) by definiton, as
others pointed out.
Presumed the important thing instead is the actual arguments do not
conform to the format, it is my pet peevee: Apple did not consider it
important enough to extend the compiler ability to test the format
string (see GCC extensions, __attribute__) to support %@ and messages.
Therefore, for NSLog (and all the messages like stringWithFormat:)
there is no compile-time checking at all :(
Apparently there is something I don't know or understand about what
happens to arguments passed to a function/method that accept a
variable number of arguments...
In principle, there is *NO* compile-time checking at all with
variable-argument list. GCC can check printf-like formats for
functions, but cannot understand %@ and cannot do so for messages,
therefore the extension is virtually unuseable.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden