By admin on

C School

C is a low level programming language used to build the linux kernel


How the C Language is Structured

C is strictly typed, this means that it requires the developer to be more code and strictly enforce types in variable assignments and passing of parameters

C is a compiled language - this means that it has to go through a build process from source code to a runtime executeable

C is not cross platform, - this means that one has to write system specific code, this is aided by macros

There are various standards (versions) of C i.e c99 c11


Talk about structuring details that make it fast


Packaging and Folder Structure

C code can also be modularised through the header files

modularised means that the code is structured then broken down into given units that function together,

this also allows for easy management of shared units such as global variables, functions or constants


so header files usually contain function declaration and macro definitions.

Header files have 2 syntaxes




Creation of a header example


main.c

#include<stdio.h>
#include"swap.h"

void main()
{
    int a=20;
    int b=30;
    swap (&a,&b);
    printf ("a=%d\n", a);
    printf ("b=%d\n",b);
}



Now the header file



header files always end in .h

swap.h

void swap (int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}



Header files are processed by the preprocessor before the compiler


Including a header twice or in different files of the same project lead to an error, to avoid this, one does a conditional prepreocesor directive , example

#ifndef HEADER_FILE_NAME
#define HEADER_FILE_NAME
   the entire header file
#endif


C code is also able to depend on external libs through the same header files,



Language Syntax










0 comments

Write a response
Publish