Monday 16 November 2015

Build Process in C/C++

With all the logic,manipulation and graphics worked out for several problems worked on. One must be curious to know how it works within.
Sequence of Events : Editor => Type the Code => Press Build & Run => Wait[Build Process]... =>Prompt/Window
Ever noticed what’s going on while those 30 seconds or 20 seconds or may be 10 seconds or 1 second of execution of your application until you see the prompt or a window appear on the screen.[WAIT..] We often do miss on the abstract processes,right?. One of them is The Build Process in C. The basic five phases of the process includes :
enter image description here
PREPROCESSING
Significant from the ‘#’ symbol also known as the preprocessor symbol in C. In this phase the "helloworld.c" source code file is preprocessed and the expanded source code is generated based in the directives like #define, #include, #ifdef etc. with "helloworld.i" extension. This is the very same time when your #define MAX 10000007 is replaced in the code before the syntactical check. i.e the defined constant is searched and matching tokens are replaced with the given expression. Also widely used as in “#include” causes the preprocessor to paste the contents of “stdio.h” into the source code file at the location of the #include statement
#include <stdio.h>
#define NEXTLINE printf("\n");

int main()
 {
 printf("The text in first line.");
 NEXTLINE
 printf("The text in the next line.");
 return 0;
 }
goes similar to this...
....
printf("The text in first line.");
printf("\n");
printf("The text in the next line.");
...

COMPILATION
The second stage include the identification of syntax errors in expanded source code "helloworld.i" If found; the syntax errors are listed on the terminal with warnings and comes back for corrections. On the other hand, error free code is translated by the Compiler into an equivalent assembly language program with "helloworld.asm or "helloworld.s" file extension. Different processors support different set of assembly instructions using which they can be programmed hence the same program on compilation with Core i3 would generate different ".asm" file than the one on compilation with Core i5.

ASSEMBLING
Once the assembler code is generated it is then translated from "helloworld.asm" file to relocatable object code"helloworld.obj" or "helloworld.o" .Its relocatable since no specific memory
address has yet been assigned to the code and data sections in this relocatable code and all the addresses are relative offsets. The '.obj' file created is a specially formatted binary files which consists of header and several sections. The header defines describes the sections that follow it which are :
text section : consists of machine language code equivalent of the expanded source code.
data section : contains global variables and their initialized values
block started by symbols : known as BSS includes the uninitialized global variables. - symbol table : contains information about the symbols found during assembling of the program e.g. names,types and size of global variables etc.

The relocatable code "helloworld.obj" consists of machine language instructions but cannot be executed directly since external functions like printf(),scanf() etc. are not present in them. You can give this one a try by visiting the obj>debug folder of any project you are working on.
Note - Any variable in an '.obj' file can be used in another '.obj' file as well as a function used in one '.obj' file can be defined in another ‘.obj’ file. This though leaves the symbol table incomplete,the references to such variables and functions are resolved by the linker.

LINKING
The Linker plays a vital role being the final stage in creation of the well known file “helloworld.exe”. It does followings -
  • it finds definition of all external functions and global variables both from other '.obj' files and external libraries
  • it combines data sections of different '.obj' files into single data section and
  • combines code sections of different '.obj' into single code section.
Re-adjustment of addresses if required is done at the time of linking. The “helloworld.exe” file includes all machine language code from all of the input object files in its text section. During linking if the linker finds any library name mis-spelled, it stops the linking process and doesn't create and executable file.

LOADING
Once the “helloworld.exe” is created by linker and stored on the secondary storage. When we execute it, its bought to the RAM by an Operating System component called Program Loader which places the executable anywhere in memory according to the availability. All addresses in the “helloworld.exe” file code are realtime and the data are position independent.
Note – Both “helloworld.exe” and “helloworld.obj” are formatted binary files and can't be used inter-platforms. e.g. Windows use Portable Executable(PE) while Linux uses Executable and Linking Format(ELF) hence .EXE file created in either cannot be used in the other.

                 ...[END WAIT] And the prompt thereby appears in front of the user.

7 comments:

  1. http://www.aiobjectives.com/

    AI Objectives is a platform of latest research and online training courses
    of Artificial Intelligence. We provide latest technology news and research
    articles on which our researcher work in Artificial Intelligence Domain such
    as in Deep Learning, Neuro-gaming, Machine Learning and Image Processing.

    Our Vision is to provide latest research in Artificial Intelligence and online
    YouTube training for free.

    ReplyDelete

  2. http://fukatsoft.com/b/bci-applications/

    Brain-computer interface (BCI) is a collaboration between a brain and a
    device that enables signals from the brain to direct some external activity,
    such as control of a cursor or a prosthetic limb.



    khadimg5544@gmail.com

    ReplyDelete

  3. To keep your audience’s attention, be sure to use a variety of images. Attempt a blend of stock photographs, standards made with the Tumblr pennant producer, infographics, images, and the sky is the limit from there.

    http://www.aiobjectives.com/2019/10/10/why-images-are-important/

    ReplyDelete
  4. Pakistan super league (Urdu: پاکستان سپر لیگ‎; PSL) is a professional twenty cricket league, based in Lahore on 9 September 2015 with five teams and now accommodates six teams. Rather than working as an affiliation of independently owned groups. The league is a single entity in which every franchise is own and controlling by way of buyers.

    ReplyDelete
  5. https://fukatsoft.com/b/section-144/



    Section 144 of the crook procedure code (CRPC) of 1973 authorizes the executive Justice of the Peace of any country or territory to trouble an order to restrict the assembly of four or greater people in an area. Consistent with the law, every member of such ‘unlawful assembly’ may be booked for undertaking rioting.

    ReplyDelete

  6. A: Apples, Apricots, Avocados

    B: Bananas, Boysenberries, Blueberries, Bing Cherry

    C: Cherries, Cantaloupe, Crab apples, Clementine, Cucumbers

    D: Damson plum, Dinosaur Eggs (Pluots), Dates, Dewberries, Dragon Fruit

    E: Elderberry, Eggfruit, Evergreen Huckleberry, Entawak

    F: Fig, Farkleberry, Finger Lime

    G: Grapefruit, Grapes, Gooseberries, Guava

    ReplyDelete
  7. The Linker plays a vital role being the final stage in creation of the well known file “https://aduk.de/”. It does followings -
    it finds definition of all external functions and global variables both from other '.obj' files and external libraries

    ReplyDelete