Re: Are method declarations just comments?
Re: Are method declarations just comments?
- Subject: Re: Are method declarations just comments?
- From: Peter Ammon <email@hidden>
- Date: Mon, 09 Jul 2001 11:07:29 -0700
on 7/8/01 2:27 AM, Andreas Monitzer at email@hidden wrote:
>
On Sunday, July 8, 2001, at 08:52 , Chris Gehlker wrote:
>
>
> I'm pretty new to Cocoa, just working my way through "Learning Cocoa" in
>
> fact. I noticed that the book was having me add methods in .m files
>
> without
>
> declaring them in the corresponding .h file and the programs were still
>
> compiling and running w/o warnings. So I went back and commented out
>
> method
>
> declarations and even changed them so they declared the wrong type of
>
> arguments. Again it didn't seem to matter. I'm beginning to fear that
>
> they're just comments. Someone say it isn't so.
>
>
It isn't so :-)
>
>
Header files are in ObjC (like in C, unlike in C++) just a hint for the
>
compiler and for the user. You can send every message you like to every
>
object, but if it's not declared in the header, the compiler will spit out
>
a warning.
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:)
-Peter