4 Replies - 2332 Views - Last Post: 04 September 2011 - 08:51 AM Rate Topic: -----

#1 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

What happens at compile-time?

Posted 04 September 2011 - 07:22 AM

This is my understanding of what happens at compile-time . . .

  • The preprocessor runs.
  • The compiler checks for errors in the code.
  • The compiler converts the code into machine code.
  • The compiler links it.
  • The exe is created.


Is the order of events in the list correct and am I missing anything out? Could you briefly explain to me how the compiler links the program?

Is This A Good Question/Topic? 2
  • +

Replies To: What happens at compile-time?

#2 Hezekiah  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 208
  • View blog
  • Posts: 552
  • Joined: 12-July 09

Re: What happens at compile-time?

Posted 04 September 2011 - 07:43 AM

That's kind of right.
- preprocessor: source code -> prepocessed code
- compiler: preprocessed code -> object file
- linker: object files -> executable

Edit: The object file is a binary file storing the definitions of functions (including function calls). The linker adds the object files together as an executable, handling calls between files appropriately. This is probably not a very good explanation, but I tried.

This post has been edited by Hezekiah: 04 September 2011 - 07:49 AM

Was This Post Helpful? 2
  • +
  • -

#3 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 625
  • Joined: 11-June 11

Re: What happens at compile-time?

Posted 04 September 2011 - 08:07 AM

A typical environment consists of six phases,

1. Editor: Programmer creates program in the editor and stores it on disk.
2. Preprocessor: Preprocessor program processes the code.
3. Compiler: Compiler creates object code and stores it on disk.
4. Linker: Linker links the object code with the libraries, creates an executable file and stores it on disk.
5. Loader: Loader puts program in memory.
6. CPU: CPU takes each instruction and executes it, possibly storing new data values as the program executes.

A bit in detail,

Phase 1: Creating a Program
Phase 1 consists of editing a file with an editor program (normally known simply as an editor). You type a program (typically referred to as source code) using the editor, make any necessary corrections and save the program on a secondary storage device, such as your hard drive.

Phase 2 & 3: Preprocessing and Compiling a Program
In phase 2, the programmer gives the command to compile the program. A preprocessor program executes automatically before the compiler's translation phase begins. Preprocessor obeys commands called preprocessor directives, which indicates that certain manipulations are to be performed on the program before compilation. Then the compiler translates the program into machine-language code (also called object code).

Phase 4: Linking
Programs typically contain references to functions and data defined elsewhere, such as in the standard libraries or in the private libraries. The object code produced by the compiler typically contains "holes" due to these missing parts. A linker links the object code with the code for the missing functions to produce an executable image.

Phase 5: Loading
Before a program can be executed, it must first be placed in memory. This is done by the loader, which takes the executable image from disk and transfers it to memory. Additional components from shared libraries that support the program are also loaded.

Phase 6: Execution
Finally, the computer, under the control of its CPU, executes the program one instruction at a time.


Hope it Helped!

This post has been edited by AKMafia001: 04 September 2011 - 08:10 AM

Was This Post Helpful? 4
  • +
  • -

#4 hulla  Icon User is offline

  • Writing Lines


Reputation: 49
  • View blog
  • Posts: 732
  • Joined: 05-March 11

Re: What happens at compile-time?

Posted 04 September 2011 - 08:15 AM

It helped alot. Thank you so much! :D

Darren what do you mean try gotoxy()? gotoxy() is used to position the cursor in DOS windows and is non-standard, along with conio.h . . .
Was This Post Helpful? 0
  • +
  • -

#5 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3124
  • View blog
  • Posts: 19,168
  • Joined: 14-September 07

Re: What happens at compile-time?

Posted 04 September 2011 - 08:51 AM

Shameless plug alert

A Visual Guide of the C++ Compilation Process
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1