Re: Function definitions
Re: Function definitions
- Subject: Re: Function definitions
- From: Ondra Cada <email@hidden>
- Date: Sun, 9 Apr 2006 01:13:48 +0200
Jonathan,
On 9.4.2006, at 0:44, Jonathan wrote:
For example, if I put this in the header file:
int sum (int value1, int value2);
Why do I need to restate it when defining the function
implementation again
in the .c:
int sum (int value1, int value2)
return (value1 + value2);
}
Isn't one or the other just superfluous?
Let's first make this question Cocoa by saying the *very* same
applies for message declarations in @interface, like
-(int)sum:(int)v1:(int)v2;
and the appropriate method definitions in @implementation, like
-(int)sum:(int)v1:(int)v2 {
return v1+v2;
}
Now, to the answer: yup, you are right, one (the declaration) is
superfluous. We could do without declarations of functions and messages.
There are a few reasons we do not:
(i) declaring them, the compiler can warn when we make a typo;
(ii) with proper declarations, the compiler can automatically and
properly cast values (typically, but not exclusively, ints to floats);
(iii) the header files make a great place for API documentation :)
---
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