Compile-Time Errors Versus Runtime Errors

Compile-Time Errors Versus Runtime Errors
Compilation vs Interpretation
High-level source code is translated into low-level machine code by a compiler. The result of a successful compilation is an executable.
Benefits of Compiled Languages:
Compilation translates high-level programming language into low-level machine language. Because of this, compiled programs may be run on any system that understands machine language.
Compilation removes redundancies or inefficiencies in source code as it is translated to machine code. As a result, compiled code is faster at run-time than interpreted code.
Downsides of Compiled Languages:
Compiled languages must be re-compiled after each set of changes are made. This makes testing compiled programs slower.
High-level source code is dynamically executed on the host machine at run time.
Benefits of Interpreted Languages:
Interpreted languages may be changed and immediately tested, without the need for re-compilation. This makes them better suited for testing environments.
Downsides of Interpreted Languages:
Interpreted programming languages are slower than compiled languages
Interpreted languages require the host machine has the required interpreter to execute the script. This makes scripts more difficult to run on systems whose implementation is unknown.
Many interpreted languages sidestep this problem by utilizing the C programming language. Python, Ruby, and Perl are all written in C.
Three Phases of Compilation
Front End:
(Sometimes) Preprocessing
Lexical Analysis
Syntax Analysis (Parsing)
Semantic Analysis
Middle End:
Low-Level Language Optimizations
Back End:
Machine-Dependent Optimizations
Code Generation
Four Lifecycle Phases of Compiled Program Execution
Compile Time:
High-level source code is translated into low-level machine code by a compiler. The result of a successful compilation is an executable.
Link Time:
A linker takes one or more object files generated by a compiler and combines them into a single executable file, library file, or other object file. There are two types of link files:
Library Types:
Static Library (Statically-Linked Library):
A set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable.
Dynamic Library (Dynamically-Linked Library):
The OS loads and links the shared libraries needed by an executable at run time, by copying the content of libraries from persistent storage to RAM.
Load Time:
A loader (part of the OS) reads the contents of the executable file containing the program instructions into memory. Once loading is complete, the operating system starts the program by passing control to the loaded program code.
Run Time:
Dynamic Libraries are bound to objects, and the program is executed.
Compilation Error, Linker Error, and Run-time Error
Compilation Error:
An error that occurs when a compiler fails to compile a piece of computer program source code, either due to errors in the code, or, more unusually, due to errors in the compiler.
Compilation error messages help programmers debug the source code.
Examples of compilation errors include syntax errors and type-checking errors.
Linker Error:
The compilation was successful, but some necessary function or library cannot be found, or does not exist.
Run-time Error:
You execute a program, and an error occurs.
There are two types of run-time errors:
Logic Errors:
Your program does not run as expected
Fatal Errors:
The executable crashes
Run-time errors include buffer overflows, division by zero, invalid memory addressing, or invalid parameter values