2. Why C, and not assembly language?
While assembly language can provide speed and maximum control of the program, C
provides portability.
Different processors are programmed using different Assembly languages and having to
choose and learn only one of them is too arbitrary. In fact, one of the main strengths of C is
that it combines universality and portability across various computer architectures while
retaining most of the control of the hardware provided by assembly language.
For example, C programs can be compiled and run on the HP 50g calculator (ARM
processor), the TI-89 calculator (68000 processor), Palm OS Cobalt smartphones (ARM
processor), the original iMac (PowerPC), the Arduino (Atmel AVR), and the Intel iMac (Intel
Core 2 Duo). Each of these devices has its own assembly language that is completely
incompatible with the assembly language of any other.
Assembly, while extremely powerful, is simply too difficult to program large applications and
hard to read or interpret in a logical way. C is a compiled language, which creates fast and
efficient executable files. It is also a small "what you see is all you get" language: a C
statement corresponds to at most a handful of assembly statements, everything else is
provided by library functions.
2
3. Why C, and not another language?
The primary design of C is to produce portable code while maintaining
performance and minimizing footprint (CPU time, memory, disk I/O, etc.). This
is useful for operating systems, embedded systems or other programs where
performance matters a lot ("high-level" interface would affect performance)
One powerful reason is memory allocation. Unlike most programming
languages, C allows the programmer to write directly to memory.
C gives control over the memory layout of data structures
Moreover dynamic memory allocation is under the control of the programmer
(which also means that memory deallocation has to be done by the
programmer).
While Perl, PHP, Python and Ruby may be powerful and support many features
not provided by default in C
3
5. C - Environment Setup 5
IDE + Compiler
Install Eclipse C/C++ Development Tool (CDT)
Java Downloads for All Operating Systems
1. Install MinGW GCC
Minimalist GNU for Windows
https://sourceforge.net/projects/mingw/file
s/
2. Cygwin GCC
https://www.cygwin.com/setup-x86.exe
Cygwin is:
a large collection of GNU and Open Source tools
which provide functionality similar to a Linux
distribution on Windows.
a DLL (cygwin1.dll) which provides substantial
POSIX API functionality.
6. Install MinGW GCC 6
Press Apply to all
Install MinGW GCC
Minimalist GNU for Windows
https://sourceforge.net/projects/mingw/files/
22. GCC Compilation Process
Pre-processing: via the GNU C Preprocessor (cpp.exe), which includes the
headers (#include) and expands the macros (#define).
cpp hello.c > hello.i
The resultant intermediate file "hello.i" contains the expanded source code.
Compilation: The compiler compiles the pre-processed source code into
assembly code for a specific processor.
gcc -S hello.i
The -S option specifies to produce assembly code, instead of object code. The
resultant assembly file is "hello.s".
Assembly: The assembler (as.exe) converts the assembly code into machine
code in the object file "hello.o".
as -o hello.o hello.s
Linker: Finally, the linker (ld.exe) links the object code with the library code
to produce an executable file "hello.exe".
ld -o hello.exe hello.o ...libraries...
22
34. Refrences
GCC and Make Compiling, Linking and Building C/C++ Applications
C Programming/Why learn C?
Getting Started with C/C++ Development Tools for NI Linux Real-Time, Eclipse
Edition
34