Re: Function definitions
Re: Function definitions
- Subject: Re: Function definitions
- From: Alan Hart <email@hidden>
- Date: Sun, 9 Apr 2006 00:00:10 +0100
On 8 Apr 2006, at 23:44, Jonathan wrote:
Hi--
I'm having a hard time getting my head around one of the concepts
in C. If a
function is already defined in the header file, why does it need to be
defined again in the .c?
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?
This isn't really a Cocoa question, but here goes ...
The rest of your code needs to know of the existence of the sum()
function. That's the purpose of the .h file. It isolates the
declaration of the function's existence, and of its interface, from
its implementation.
If the .h file didn't exist you'd have to build the whole of your
application in one file, or #include the whole of that .c file in
every other .c file that wants to call sum(), and then every file in
your project would get recompiled any time you changed one line in sum
(). And you'd get tied up in knots working out which file was
#including which.
Alan
_______________________________________________
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