Introduction
We know that a compiler converts a high-level language source code to a low-level machine language. There are various types of compilers, such as traditional compilers, interpreters, incremental compilers, converters, etc. But do you know that a cross-compiler is also a type of compiler.

Do you know what cross-compiler are and how they work? If not, then don't worry because, in this article, we will discuss about compiler vs cross compiler. We will see their working, advantages and disadvantages. In the end, we will also see a difference table to better understand about a compiler and a cross compiler.
Compiler
A compiler converts a source code of a high-level language to a low-level machine language without modifying the code's definition, and the compiler's end code is optimized for memory space and time.

The compiler accepts a high-level language as its input, and the output is a machine code that is executable for the same platform as the compiler. A compiler uses libraries specific to the platform. It has an easy setup.
Working of a Compiler
The compilation work mainly involves the following phases:
-
Lexical Analysis: It is the starting Phases of Compiler in which modified source code is gathered. A lexical analyzer breaks syntax into a series of tokens by removing white spaces.
-
Syntactic analysis: It is the process in which a string of symbols is analyzed either in computer language, data structures, or natural language.
-
Intermediate code generation: A compiler generates a middle-level language during the translation of a source program into object code for the target machine. This is known as Intermediate code generation.
-
Optimization: It is the process in which any space/memory optimization if needed, are analyzed.
-
Code generation: This step includes the final generated code that should have the same meaning as the source code.
For different computer architectures, different machine code is produced. This means that a program that is compiled for one type of computer will not necessarily run on a computer with different architecture. A compiler generates an executable file, i.e., .exe. An example of a compiler would be the GCC compiler or Turbo C.
There are various types of compilers, such as traditional compilers, interpreters, cross-compilers, increments compilers, converters, Just-in-time (JIT) Compilers, Single-Pass Compilers, Multi-pass compilers, Ahead-of-Time (AOT) Compilers, etc.
Advantages of Compiler
Let's discuss some of the advantages of a compiler.
-
A compiler analyses the source code and produces a machine code. The machine code produced is specific to that particular computer’s architecture.
-
Syntax and logical errors are also identified in the compilation process done by the compiler.
-
Compilers are able to perform various optimizations, like function inkling, instruction scheduling, and unrolling.
-
They can produce code that is highly optimized and runs quickly on the same system. Therefore a compiler runs faster than a code that is interpreted.
- The compiled code can run on a computer of the same architecture as the one on which it was compiled. This shows that a compiler is portable.
Disadvantages of Compiler
Let's discuss some of the disadvantages of a compiler.
-
Compilers are not suitable for cross-platform development, as cross-platform development requires the ability to compile code for different operating systems and hardware.
-
A compiler is platform-dependent as the compiled code can run on a computer of the same architecture as the one on which it was compiled.
- Debugging a compiled code can be a tedious and difficult task compared to the code interpreted by the interpreter.