Changes

An Overview of Objective-C Functions

1,263 bytes added, 19:50, 20 October 2009
Calling an Objective-C Function
== Calling an Objective-C Function ==
 
Once a function is declared it can be called from anywhere in the code, regardless of whether the code is in the same source file as the declaration or in a different file. This is because functions are global by default. After the different source files have been compiled to object code, a tool called the ''linker'' then performs the task of resolving undefined symbols in each object file. When it finds a call to an undefined function in one object file it searches the other object files that comprise the code until it finds it. If no match is find the linker will fail with an undefined symbol error.
 
Functions are called using the following syntax:
 
<tt><function name> (<arg1>, <arg2>, ... )</tt>
 
For example, to call a function named ''displayit'' that takes no arguments and returns no value, we would write the following code:
 
<pre>
displayit()
</pre>
 
To call a function called ''multiply'' that take two arguments and returns an integer we might write the following code:
 
<pre>
int result;
 
result = multiply (10, 20);
</pre>
 
In the above example, we have created a new variable called result an then used the assignment operator (=) to store the result returned by the multiply function when it is passed the numbers 10 and 20 as arguments.
== Function Prototypes ==