C_Programming
First Session
ENG. KEROLES SHENOUDA
1
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
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
Compilation Process 4
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.
Install MinGW GCC 6
Press Apply to all
Install MinGW GCC
Minimalist GNU for Windows
https://sourceforge.net/projects/mingw/files/
Install MinGW GCC 7
Wait until downloading Complete
Install MinGW GCC 8
Install MinGW GCC 9
En you can see all the basic packets
became green
Install MinGW GCC 10
Then you can see the
gcc and gdb and other
binary utilities installed
(Native Toolchain )
Eclipse C/C++ (CDT) 11
 Install Eclipse C/C++ Development Tool (CDT)
 Java Downloads for All Operating Systems
Write first C Program
 Open Eclipse
 Chose an empty Directory For eclipse workspace
12
Write first C Program 13
Write first C Program 14
Write first C Program 15
Write first C Program 16
Write first C Program (Build the
Application)
17
Write first C Program (Run the
Application)
18
After Press Run,
Then you will see the
Printf message appearing
On the Console
Write first C Program (Debug the
Application)
19
Write first C Program (Debug the
Application)
20
Stopped
on the
Breakpoint
Write first C Program (Debug the
Application)
21
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
GCC Compilation Process LAB 1
on Ubuntu
23
GCC Compilation Process LAB 1
on Ubuntu
24
GCC Compilation Process LAB 1
on Ubuntu
25
GCC Compilation Process LAB 1
on Ubuntu
26
GCC Compilation Process LAB 1
on Ubuntu
27
Compilation Process 28
First C Program “Hello Program” 29
30
31
Chapter 1:
Introduction
HTTPS://DRIVE.GOOGLE.COM/FILE/D/0B7KUSGPVTWFLAEZDWLZEZM0XS0U/VIEW
32
C Programming Data Types 33
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

C programming first_session

  • 1.
  • 2.
    Why C, andnot 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, andnot 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
  • 4.
  • 5.
    C - EnvironmentSetup 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 GCC6 Press Apply to all Install MinGW GCC Minimalist GNU for Windows https://sourceforge.net/projects/mingw/files/
  • 7.
    Install MinGW GCC7 Wait until downloading Complete
  • 8.
  • 9.
    Install MinGW GCC9 En you can see all the basic packets became green
  • 10.
    Install MinGW GCC10 Then you can see the gcc and gdb and other binary utilities installed (Native Toolchain )
  • 11.
    Eclipse C/C++ (CDT)11  Install Eclipse C/C++ Development Tool (CDT)  Java Downloads for All Operating Systems
  • 12.
    Write first CProgram  Open Eclipse  Chose an empty Directory For eclipse workspace 12
  • 13.
    Write first CProgram 13
  • 14.
    Write first CProgram 14
  • 15.
    Write first CProgram 15
  • 16.
    Write first CProgram 16
  • 17.
    Write first CProgram (Build the Application) 17
  • 18.
    Write first CProgram (Run the Application) 18 After Press Run, Then you will see the Printf message appearing On the Console
  • 19.
    Write first CProgram (Debug the Application) 19
  • 20.
    Write first CProgram (Debug the Application) 20 Stopped on the Breakpoint
  • 21.
    Write first CProgram (Debug the Application) 21
  • 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
  • 23.
    GCC Compilation ProcessLAB 1 on Ubuntu 23
  • 24.
    GCC Compilation ProcessLAB 1 on Ubuntu 24
  • 25.
    GCC Compilation ProcessLAB 1 on Ubuntu 25
  • 26.
    GCC Compilation ProcessLAB 1 on Ubuntu 26
  • 27.
    GCC Compilation ProcessLAB 1 on Ubuntu 27
  • 28.
  • 29.
    First C Program“Hello Program” 29
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
    Refrences  GCC andMake 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