What is the difference between a library and an API?
API: application programming interface. It is basically an outside code that got abstracted away and meant to interface with your own code. This means a library is an API since it is code written by either others or yourself which hides away inner details and only provides an entry point aka an interface, for the rest of your code to call on and interface with. this also means restful endpoints that you do http requests(GET, POST, PATCH ect) are apis as well, (called web apis) since you are invoking and interfacing with some handler/functions in the server applications to perform some tasks from your client application. The idea is that api inner workings are abstracted away and only expose an entry point for your code to interface with. For the library, this entry point is whatever the function signature is, for rest endpoints, it is the HTTP protocol and whatever parameters/payload that rest endpoints accept. Operating system calls are very much like an api if you think about it. you move some xyz input into registers, including the interrupt code for a particular service you would like to invoke, and then you do a syscall with it.
library: typically packages, files, and binaries with lots of APIs. the c stdlib is referred to as libc. on Linux operating system, it is a compiled library in which many native applications and binaries are linked dynamically at run time. This is why if you delete that, you will bork your systems.
libc is not exclusive to C btw. many programming languages as well as the software coded with non-C language might linked to them.
e.g. this is how you dynamically link to a c library in Java
Calling C From Java Is Easy – The Mindful Programmer (jonisalonen.com)
this is how you do it in Python
1. Extending Python with C or C++ — Python 3.12.2 documentation
Edit: this is the correct link
Edit: windows syscalls are not meant to be used directly. microsoft expects developers to use whatever system libraries and utilities they provide as a wrapper for them. You can still try but they are not publicly documented and I am pretty sure only their internal developers ever work on them.
Assembly Syscalls in 64-bit Windows - Stack Overflow
QuoteThe only way to call Windows operating system functions in a way that it is guaranteed that your program is still working after the next Windows update is to call the functions in the
.dll
files - just the same way you would do this in a C program.
so yeah, you should probably just linked to microsoft dlls instead of reinventing the wheels. For Windows, this is the Kernel32.dll which is basically where the win32 apis come from. Note, win32 is not part of the libc. completely separate things. although on linux, the libc is analogous to kernel32.dll on windows since it is usually the lowest level codes that interface with the kernel directly and is pretty much system-wide unlike what's found on windows(windows libc is compiler specific). This makes me wonder.... what will happen if you delete kernel32.dll on windows? will it bork the os?
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now