in reply to Newbie programming questions
1. API - what are they? Are these also known as DLLs or Libs or header files? Can .exes be called APIs?
The "I" is for Interface. It covers anything that allows one program to call functions in another program. APIs are sets of rules, not files.
2. Build - Process of compilation. Right?
Yes, and linking and any other step needed to create the executable or deliverable. Furthermore, sometimes build can also mean to compile (and such) everything unconditionally, as opposed to make, which would mean to only compile (and such) missing and outdated files.
3. Compilation - Does compilation in C produce .exe or .DLL or anything else? What I understand by compilation is that source code gets converted to some binary format and some linking takes place. I don't understand what all gets linked in this process. What exactly happens in the computer memory in this process?
4. Linking - Linking of necessary fucntions. Right?
Compilation is the process of going from source code to machine code. The output is usually an object file (.obj in Windows). The object files are linked together into an executable (.exe), a statically linked library (.lib) or a dynamically linked library (.dll).
5. Run - Run is used to execute the binary (.exe or .dll?) produced by Compilation. Do other functions/system resources required by the source code (that generates the .exe) reside within the .exe or are they used externally as and when when .exe requires them? What exactly happens in the computer memory in the Run process?
Code and data can be embedded into the executable, or kept seperately. The answer to the last question is dependant on OS and architechture, dependant on how much detail you want, and does not need to be known by 99.9% of programmers.
6. DLL - Not too clear about it. How and what are being linked here. Also, what's the motivation, necessity of making a DLL in the first place? Why shouldn't I make an .exe instead of this?
Loosely, it's a bunch of compiled functions. A program can load a dynamicly linked library into memory at run-time and call the functions within it. Each of the following two paragraphs are an example where DLLs are useful.
Plugins. A program to be expanded without having the source code for the program just by creating a DLL containing functions expected by the program. (These functions are an example of an API.) Perl uses this concept to allow people to build modules without having to rebuild perl everytime. The module is compiled into a DLL, which perl tries to locate when DynaLoader(?) is used.
Operating System Calls. Every call to Windows is actually a DLL call. Without the Dynamic aspect provided by Dynamically Linked Library, the whole OS and every program you will ever use would need to be compiled at once into one big executable.
7. Exe - A standalone program. But, can such programs function in the absence of compiler say visual studio or something?
The compiler is no longer needed. This is the difference between interpreted programs from compiled programs. Nowadays, we also have programs that run in a virtual machine, which I won't get into unless asked.
8. Libs (library) - It is a collection of functions. Right? Does that mean that it is a single file that contains definitions of other functions in a project? What is its importance, motivation of having it? Are they used through some header file?
Similar to a DLL, in so much as they are a collection of compiled function. However, these are linked into the .EXE (or .DLL) at compile-time, so you don't need to have the library file present at run-time.
9. Header file - Its a collection of functions. Can it also be called a Lib? What's the difference between Lib and header file?
Header (.h) files are no different then .c (or .cpp) files. They can contain anything that can be found in a C/C++ source file. The only difference is how they are used: .h files are not compiled by themselves; they are inlined into the .c or .cpp file that #include them. Conventionally, they include function prototypes, declerations of types and defintions of constants.
They are not libraries; they are just C or C++ source code.
10. Function/subroutine/method - I guess loosely they all mean the same. Right?
Function and subroutine usually mean the same thing. In some languages (Pascal, QBasic, maybe Visual Basic), functions return a value, whereas subroutines do not.
Methods are a special type of functions. They are functions that belong to an class, and supply a "hidden" argument (known as this or self) holding a reference to the object on which the method is currently acting.
11. Broadly, what are the associations and differences between APIs, DLLs, Header files, Libs, linking etc.
They're are no relations except those mentioned above.
Sounds like you'd find a C (or C++) course interesting. You'd probably also enjoy a course in assembler programming.
|
|---|