Re: Function definitions
Re: Function definitions
- Subject: Re: Function definitions
- From: Derrick Bass <email@hidden>
- Date: Sun, 9 Apr 2006 04:24:47 -0500
On Apr 8, 2006, at 7:58 PM, Jonathan wrote:
Couldn't you just do the declare in the header:
int sum (int value1, int value2);
and then just use the function you just declared in the function
implementation:
sum ()
{
return (value1 + value2);
}
Theoretically yes, one could have designed the language that way (at
least in C). (In C++ you could not do this, because you can have
several functions with the same name that take different types and/or
numbers of arguments.) But that's just not the way it works because
of the way the language was originally defined and how it evolved
from there. As others have mentioned, header files are essentially
optional, so all the information for a particular function needs to
be available in the implementation file.
I'm also not so sure it would be good style, since someone wanting to
understand your sum function would need to look up the variable names
and types in the header file. (Although you have to do this for C++
and Objective-C classes anyway, so maybe no one would mind.)
In any case, it is annoying to have to type (or copy and paste) this
information twice, and then keep it synchronized in the face of
changes, but the time required is pretty trivial compared to the time
actually spent coding, so I don't think anyone would have the
appetite to break C for the sake of changing it.
Derrick
_______________________________________________
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