Compilation : GCC transforms the source files to an executable file. Compilation is a multi-stage process involving several tools. e.i GNU compiler, GNU assembler, GNU linker Id. The complete set of tools used in compilation is referred to as toolchain.
preprocessing : to expand the macros and included headers.
compilation : source code to assembly language (processor specific )
assembly : from assembly to machine code
linking : linking all the object files to create the final exe file
ELF : Executable and Linking format
Common ERROR Messages ::
(i) Preprocessor error messages :
a. No such file or directory : if gcc cannot find the requested file on its search path. Either spelled incorrectly or directory for the file needs to be added to include the path.
b. macro or ‘#include’ recursion too deep | #include nested too deep : if the preprocessor encounters too many nested ‘#include’ directives. occurs when 2 or more files try to include each other, leading to an infinite recursion.
c. invalid preprocessing directive# : this indicates unrecognized # command.
d. warning : This file includes at least one deprecated or antiquated header : inclusion of old style library headers.
(ii) Compiler error messages :
a. variable undeclared : in C and C++ must have variables declared before it is used.
b. parse error before ‘…’ syntax error : occurs when compiler encounters unexpected input.
c. parse error at end of input : end of file unexpectedly encountered.
d. implicit declaration of function : when a function is used without a prototype.
e. unterminated string or character const
f. character constant too long
g.warning: initialization makes integer from pointer without a cast
h. dereferencing pointer to incomplete type.
i. warning: unknown escape sequence ‘…’
j. warning : control reaches end of non-void function
MAJOR Runtime Error :
a. segmentation fault or bus error : indicate memory access error. Common causes : dereferencing a null pointer or uninitialized pointer, out-of-bound array access, incorrect use of malloc, free and related functions, use of scanf with invalid arguments.
There is subtle difference between segmentation faults and bus errors. A segmentation fault happens when a process tries to access memory protected by the operating system. A bus error happens when valid memory is accessed in incorrect way.
b. floating point exception : is caused by an arithmetic exception, such as division by zero, overflow, underflow or an invalid operation. The OS determines which condition produce this error. On GNU systems, the fucntions feenableexcept and fedisableexcept can be used to trap or mask each type of exception.
c. Illegal instruction : produced by OS when an illegal machine instruction is encountered. Occurs when code has been compiled for one specific architecture and run on another.