Friday, September 27, 2013

Footnote of C

In C main components are its keywords, variable & const , functions etc.

  • This language have reserve keywords to indicate something. We cannot use these keywords to indicate anything else. 
  • Variable :- These are memory blocks to hold values. Each variable has a type. Variables are mutable i.e. change in the variable content will change the content of respective memory block.
  • Data type :- A data type represents a system to indicate the type of data, like size and its functionality. We have no class concept in C so in build in libraries the definition of basic data type like int, char, float etc are given. We can build our own data type using typedef, Structure, union and enum .   
  • Pointer :-  Pointer is a variable stores the l-value of another variable in the virtual memory. In C pointer has constant size but it also hold the the type of data it is pointing to. We can manipulate the values in the pointed location by a process called de-referencing.  
  • Constant is a variable with constant or fixed value. This be stored in static position in function activation, we will see later what is static position.
  • Array :- Consecutive memory blocks from same type where the array name is representing a pointer holding the 1st memory address of those blocks. Array are normally statically allocated allocated. They could be dynamically allocated by malloc, calloc, realloc. 
  • Structured Programming :- In C part of code inside a '{'  and corresponding '}' represents a block or bundle of code to be executed as a group.  A block represents a complex task  formed by sequence of simpler tasks. Ex. eating could be a block consist of -         
    • picking up food by hand, put it in mouth,    
    • chew in mouth and pass the food  to digestion system, 
    • if  still fill hungry and there is more food  then                                                                           go to the step 1.
    C implements block as simply some lines in '{}' or a loop or a function or structure,union, enum etc.
  • Pre-process :- C facilitates pre-process using command after '#' directive. In pre-process it defines some strings as something, includes files/headers, check by #ifndef or #ifdef and #endif pairs etc.
  • Function  :- C use system stack to implement recursion of repeating code segments. Functions in C is like mathematical functions which take some input and generates some output. We supply some variable's value to the function (Call by value) and it give output to the calling function or manipulate some memory places used/generated by that program or manipulates std streams/files (stdin,stdout,stderr) or some other file in memory.  
  • Function Pointer :- In C a function pointer points to the executable code of a function in memory. We can call the function by the function pointer.
  • Function Call :- A function is been called by de-referencing its function pointer. Unlike copy-rule of sub-routine here we create an Activation Record holding current values in all local and temporary variables  ( while constant and static as well as global variables  and function's executable codes will be in Static Storage ). Each activation record will have a Current Instruction pointer to the next instruction of the calling function and Current Environment pointer to the calling activation.
  • Procedural Code :-  C normally read and execute the program file from the top to bottom ( This is called execution path or control flow direction ). The execution start from 'main' function. From there multiple functions are called in execution path. The function call take the control the called function's executable code. 
  • Memory Management :- C normally split the virtual memory mainly in Static, Heap and Stack and Un-allocated zone. The heap and stack are taking their requirement from the Un-allocated zone from both side of it.
    Stack consist of data of Activation Records. Heap has dynamic memory allocated blocks.
  • Scope and Lifetime :- A variable or functions scope is the span of code up to which it can be accessed [ That is if the control is in the scope of some variable it could be accessed by the control ]. A variable's life time is the range of code till which the variable will hold a position in memory. Nb. A dead variable cannot have scope but the reverse is possible. [1] .

Programming Languages of Digital Computer

When using a digital computer we actually create programs and run them.

Computer :- A machine whose Processing stage in its IPO cycle is nothing but computation.

We call a program as a software normally if it interacts with the user  in direct or indirect way.
You can burn a microprocessor with a program which only consist of an infinite loop and never give  or take any output/input respectively, but that will not be a software.

Programs are sequence of bits to represent a sequence task to be done by Computer. Program are written in some language.

String :- A sequence of symbols belongs to an alphabet corresponding to a language.
Language :- A set of strings generated from the alphabet of that language.
Every language has a grammar.
Grammar :- The set of rules to generate exactly those strings which belongs to that language.

In the computation syntax represent the grammar. A string is syntactically correct  means it is generated following the grammar of that language.

However semantics tells the meaning of the language. It is usually very important to map a string of an language to equivalent string in another language ( Actually 'meaning' has an implicit hint that we want to translate or map the string in an language to some sequence image/symbols residing in out brain i.e. the implicit language of brain ).

For example :- When a person tells to another person  that "I Love You" at that moment the feeling / image of love generates in the person who received that voice. :) But if one say "I want to dance with you." the sequence of dancing moment will rise in your mind.

Practically in the sense of computer science the semantics does only above mentioned work. But for linguistics the semantics also decide validity of a sentence. (But in the computing languages the invalid sentences could not pass the grammar test.)

 Programming languages are a subset of computational languages as one programming language is  valid under a certain environment. Suppose there is no concept of memory allocation in some computing device like PLD , there some code in C language has no meaning. But mostly all well known programming language can work on the common digital computers so we can just avoid this point as we are by default assuming to talking about normal digital computers PC or higher level.

In the context of normal computers the programming language is the set of string in which user can express his wish of some task to be done by that computer and that  could be translated to the equivalent Machine code to execute the desired task.