I am new to programming. learning C as of now. I understand that header file only contains the declarations and function prototypes, not the functions themselves. Am I correct?
I understand that Library is a single file that contains different object codes. Are these object codes necessarily written only in C language or other languages can also be used to generate such object codes?
On linking, does the entire library file get attached to the executable or just the object codes declared in the header file?
I understand that header file only contains the declarations and function prototypes, not the functions themselves.
Usually, yes (although you can theoretically put any code you want in a header file). Remember that a header file is usually just #include
-d into a source file, and #include
is basically equivalent to a copy-and-paste.
I understand that Library is a single file
Not necessarily. "Library" is a bit of a loose term, but generally speaking, it's used to describe a collection of functions (and potentially data) that together perform some useful set of tasks. These functions may be defined in one or several source files. Typically, a library is pre-compiled into a standalone object file. But again, not necessarily.
Are these object codes necessarily written only in C language
No. They can be written in any language (because it will always be compiled down to raw machine code). But if you want to use the library from C, then certain compatibility requirements must be fulfilled, to ensure that the C compiler knows how to call the library functions correctly.
On linking, does the entire library file get attached to the executable
Sometimes. This is what's known as static linking. The other main type is dynamic linking, where the library object code is linked at run-time.
I understand that header file only contains the declarations and function prototypes, not the functions themselves. Am I correct?
Yes, in most cases. Code can appear in headers which the compiler will try to "inline" (look that up).
Are these object codes necessarily written only in C language or other languages can also be used to generate such object codes?
They can be written in any complied language but the most common are C and C++.
does the entire library file get attached to the executable or just the object codes declared in the header file?
Linking just tells the executable how to call the underlying the library code, it does not "attached" the library unless you are doing "static" linking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With