• 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: Are method declarations just comments?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Are method declarations just comments?


  • Subject: Re: Are method declarations just comments?
  • From: Peter Ammon <email@hidden>
  • Date: Mon, 09 Jul 2001 14:21:08 -0700

on 7/9/01 11:32 AM, Andreas Monitzer at email@hidden wrote:

> On Monday, July 9, 2001, at 08:07 , Peter Ammon wrote:
>
>> Unless I'm mistaken, Objective-C is actually more lax about requiring
>> function declarations. For example, C requires that variadic functions
>> (that is, functions with a variable number of arguments like printf) be
>> prototyped, whereas AFAIK Objective-C places no such requirements on
>> variadic methods (e.g. arrayWithObjects:)
>
> I never really programmed C without function declarations, but AFAIK all
> non-declared functions are treated with variable arguments like
> int func(...)
>

It can't be int func(...) because that's not a legal signature; all variadic
functions must have at least one "guaranteed" parameter.

Here's my understanding: If you call a function foo(3, 2.5, "hello") before
prototyping foo, then C assumes that there is a function foo that returns
int with a signature int, double, char*. If foo does not have that
signature, then the behavior is undefined. If foo were at all variadic, it
wouldn't have that signature, so there's no way to legally call a variadic
function before prototyping it.

On the other hand, all methods in Objective-C are invoked using
objc_messagesend (or whatever it's called), which is itself a variadic
function, so passing the "right" number of parameters makes no difference to
objc_messagesend. And, of course, objc_messagesend figures out the
signature of the method it calls at runtime, so no prototypes are necessary
at compile time, even for variadic methods.

I hope this makes some sense and that I didn't make too many mistakes.

-Peter


References: 
 >Re: Are method declarations just comments? (From: Andreas Monitzer <email@hidden>)

  • Prev by Date: Re: NSTableView--responding to clicks
  • Next by Date: Re: NSTableView--responding to clicks
  • Previous by thread: Re: Are method declarations just comments?
  • Next by thread: Re: Are method declarations just comments?
  • Index(es):
    • Date
    • Thread