Page 115 - C-Language
P. 115

executed. Binary executables have no special suffix on Unix operating systems, although
              they generally end in .exe on Windows.
              e.g., foo foo.exe


            5.  Libraries: A library is a compiled binary but is not in itself an an executable (i.e., there is no
              main() function in a library). A library contains functions that may be used by more than one
              program. A library should ship with header files which contain prototypes for all functions in
              the library; these header files should be referenced (e.g; #include <library.h>) in any source
              file that uses the library. The linker then needs to be referred to the library so the program
              can successfully compiled. There are two types of libraries: static and dynamic.

                  •  Static library: A static library (.a files for POSIX systems and .lib files for Windows —
                    not to be confused with DLL import library files, which also use the .lib extension) is
                    statically built into the program . Static libraries have the advantage that the program
                    knows exactly which version of a library is used. On the other hand, the sizes of
                    executables are bigger as all used library functions are included.

                    e.g., libfoo.a foo.lib
                  •  Dynamic library: A dynamic library (.so files for most POSIX systems, .dylib for OSX
                    and .dll files for Windows) is dynamically linked at runtime by the program. These are
                    also sometimes referred to as shared libraries because one library image can be
                    shared by many programs. Dynamic libraries have the advantage of taking up less disk
                    space if more than one application is using the library. Also, they allow library updates
                    (bug fixes) without having to rebuild executables.

                    e.g., foo.so foo.dylib foo.dll

        The Preprocessor


        Before the C compiler starts compiling a source code file, the file is processed in a preprocessing
        phase. This phase can be done by a separate program or be completely integrated in one
        executable. In any case, it is invoked automatically by the compiler before compilation proper
        begins. The preprocessing phase converts your source code into another source code or
        translation unit by applying textual replacements. You can think of it as a "modified" or "expanded"
        source code. That expanded source may exist as a real file in the file system, or it may only be
        stored in memory for a short time before being processed further.


        Preprocessor commands start with the pound sign ("#"). There are several preprocessor
        commands; two of the most important are:

            1.  Defines:


              #define is mainly used to define constants. For instance,


               #define BIGNUM 1000000
               int a = BIGNUM;


              becomes


               int a = 1000000;



        https://riptutorial.com/                                                                               91
   110   111   112   113   114   115   116   117   118   119   120