[Courses] C Programming For Absolute Beginners, Lesson 5: All About Functions, part 1
Sachin Divekar
ssd532 at gmail.com
Wed Mar 14 01:57:18 UTC 2012
>
> code:
> ----------
> // file main.c
>
> int myadd (int, int);
>
> int main ()
> {
> return myadd (3, 2);
> }
>
> // file add.c
> int myadd (int a, int b)
> {
> return a + b;
> }
>
> // You would then compile and link the two files together with this command:
>
> gcc main.c add.c -o myprogname
What is the difference between using #include and linking together
using gcc as shown in above example?
> ----------
>
> Though, as I said, it is usually more sensible to put the prototype in a
> separate file and #include it among the various files that need it. With
> shared libraries (utilizing dynamic linking), you also #include a
> prototype from a header, but the real function is not provided at all
> during compiling! Rather, it is provided later by the system at the
> beginning of the program's execution. This allows people to code their
> programs for a particular library interface (i.e., set of function
> prototypes) while the library functions themselves may differ somewhat
> from system to system. (For example, depending on the special needs of
> the system. This is how OpenGL still works, even though we all have
> different graphics cards.)
>
Can somebody please elaborate this paragraph?
Thank you.
--
Regards,
Sachin Divekar
More information about the Courses
mailing list