While working on an assignment I am asked to implement several APIs. I am wondering what this means, as they are described as functions. What steps should I take to write an API, and how would this effect my actual program?
While working on an assignment I am asked to implement several APIs. I am wondering what this means, as they are described as functions. What steps should I take to write an API, and how would this effect my actual program?
Basically, you're supposed to create a library of functions with some common theme.
For example, a graphics library would have circle, line, colour functions.
The group of functions you provide form an API.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Alright, that seems to make sense. If I then wanted to call that set of functions, I'd need to have them in some .h file? Thanks for your help.
Yes. You need .h's available as #includes for users of the API.
As Salem implies, an API generally belongs to a library. I think the simplest definition of a library WRT to C is that it is an executable object compiled from source without a main(), with the intention that it be linked to (used by) another executable object that does have a main() (and so is a full fledged "application").
So you write the library, and the API is basically the list of functions, types, etc. available to anyone who wants to write an application using that library. For example, the C API is all the functions, types, etc that are part of the standard C library.
Last edited by MK27; 10-24-2011 at 09:50 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge
Alright, I think I have a good grip on what an API is and how to use/implement it, thanks again for both of your help.