• 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: [Somewhat-OT]?Unexpected behaviour of variable argument lists
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Somewhat-OT]?Unexpected behaviour of variable argument lists


  • Subject: Re: [Somewhat-OT]?Unexpected behaviour of variable argument lists
  • From: Matt Neuburg <email@hidden>
  • Date: Thu, 16 Sep 2004 15:01:04 -0700

On Thu, 16 Sep 2004 17:54:42 +0200, Ondra Cada <email@hidden> said:
>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 :(

This has long bothered me as well. Getting the number of arguments wrong
after a format is a nice way to crash at runtime, so one wishes the compiler
would warn.

On the other hand, the fact that you can say @"one" @"two" as a way of
concatenating two strings is an extremely useful feature of Objective-C, one
that I use all the time to make code more readable by breaking up long
strings into pieces on separate lines. m.


--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide
<http://www.amazon.com/exec/obidos/ASIN/0596005571/somethingsbymatt>



 _______________________________________________
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

  • Follow-Ups:
    • Re: [Somewhat-OT]?Unexpected behaviour of variable argument lists
      • From: Scott Ribe <email@hidden>
  • Prev by Date: Re: All IBOutlet instance variables show 0x0 - they're not there?! XCode bug?
  • Next by Date: Re: build numbers
  • Previous by thread: Re: Alpha Channel in real time
  • Next by thread: Re: [Somewhat-OT]?Unexpected behaviour of variable argument lists
  • Index(es):
    • Date
    • Thread