Introduction to C – Advantages, Compiler, Namespaces – Part1


Advantages of C

  • very good performance, Code is compiled and executed on the operating system. No interpretation, such as Java, Code can only be executed by the JVM
  • it can also be installed C, selber Compiler: GNU C-Compiler

Advantages of C over the previous C

  • stricter type checking, runtime / LateBinding
  • Object orientation possible
  • improved memory management
  • Exceptions Handling

The C compilation process: How does the GNU compiler?

  1. x.cc and x.h as output files
  2. x.i, Header files include, Hardware platform query, Preprocessor directives execute (e.g.. #define, Variables / functions will be replaced in the code)
  3. x.o, mit C Compiler g , Generate machine code assembler, This is hardware- and operating system dependent
  4. Linker writes the addresses of the libs and links all object files (.the) together
  5. x.exe, executable shell file generate

Declaration, Definition, Initialization and assignment in C

Declaration

  • No memory allocation
  • as often as possible
inf f(char c);
extern char c;
inf f(char c);

Definition

  • Creating objects in memory
  • is a declaration
  • only once
inf f(char c){return 'a';};
char c;

Initialization

  • Assigning values
inf a = 1;

Allocation

  • Change uninitialized values
inf a = 1;//Initialisierung
a = 2; //Zuweisung

Namespaces in C

  • Avoid naming conflicts with same function names / variables
  • Elements within a namespace must always be used, specifying the namespaces, Exception using
namespace A{
 void f(){cout "lala"};
}
void main()
{
A::f();// lala
//ODER
using A;
f();//lala
}

Special case:

namespace A{
 void f(){cout << "lala"};
}
void main()
{
void f(){cout << "blub"; }
using A;
f();//blub
A::f();//lala
}

Allocation prioritization ambiguous function names

  1. premises Block (highest Prio)
  2. parent block
  3. Namespace mit using

Nesting namespaces

namespace A{
 namespace B{f();};
};
A::B::f();

 

Contents:

Introduction to C - Advantages, Compiler, Namespaces - Teil1

Introduction to C - Pointer, Pointer,References - Part2

Introduction to C - Data Types, Casting, Classes - Part 3

Introduction to C - Functions and Operator Overloading (Overloading) - Part4

Introduction to C - Classes: Heredity, Adjustment, Friends, abstract - Part5