Page 117 - C-Language
P. 117

will be changed to:


               variable = another_variable + 1;


              if A or B were defined somewhere in the project before. If this is not the case, of course the
              preprocessor will do this:


               variable = another_variable * 2;


              This is often used for code, that runs on different systems or compiles on different compilers.
              Since there are global defines, that are compiler/system specific you can test on those
              defines and always let the compiler just use the code he will compile for sure.


            4.  Comments

              The Preprocessor replaces all comments in the source file by single spaces. Comments are
              indicated by // up to the end of the line, or a combination of opening /* and closing */
              comment brackets.


        The Compiler


        After the C pre-processor has included all the header files and expanded all macros, the compiler
        can compile the program. It does this by turning the C source code into an object code file, which
        is a file ending in .o which contains the binary version of the source code. Object code is not
        directly executable, though. In order to make an executable, you also have to add code for all of
        the library functions that were #included into the file (this is not the same as including the
        declarations, which is what #include does). This is the job of the linker.


        In general, the exact sequence how to invoke a C compiler depends much on the system that you
        are using. Here we are using the GCC compiler, though it should be noted that many more
        compilers exist:


         % gcc -Wall -c foo.c


        % is the OS' command prompt. This tells the compiler to run the pre-processor on the file foo.c and
        then compile it into the object code file foo.o. The -c option means to compile the source code file
        into an object file but not to invoke the linker. This option -c is available on POSIX systems, such
        as Linux or macOS; other systems may use different syntax.

        If your entire program is in one source code file, you can instead do this:


         % gcc -Wall foo.c -o foo


        This tells the compiler to run the pre-processor on foo.c, compile it and then link it to create an
        executable called foo. The -o option states that the next word on the line is the name of the binary
        executable file (program). If you don't specify the -o, (if you just type gcc foo.c), the executable will
        be named a.out for historical reasons.




        https://riptutorial.com/                                                                               93
   112   113   114   115   116   117   118   119   120   121   122