Question JS05 - Nur Amira Aqilah Bnti Latif

3
QUESTION/DISCUSION 1. How to a. Compilation process The compilation of a C++ program involves two steps: Compilation Compilation refers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces the machine language instructions that correspond to the source code file that was compiled. For instance, if you compile (but don't link) three separate files, you will have three object files created as output, each with the name <filename>.o or <filename>.obj (the extension will depend on your compiler). Each of these files contains a translation of your source code file into a machine language file -- but you can't run them yet! You need to turn them into executables your operating system can use. That's where the linker comes in. Linking Linking refers to the creation of a single executable file from multiple object files. In this step, it is common that the linker will complain about undefined functions (commonly, main itself). During compilation, if the compiler could not find the definition for a particular function, it would just assume that the function was defined in another file. If this isn't the case, there's no way the compiler would know -- it doesn't look at the contents of more than one file at a time. The linker, on the other hand, may look at multiple files and try to find references for the functions that weren't mentioned. You might ask why there are separate compilation and linking steps. First, it's probably easier to implement things that way. The compiler does its thing, and the linker does its thing -- by keeping the functions separate, the complexity of the program is reduced. Another (more obvious) advantage is that this allows the creation of large programs without having to redo the compilation step every time a file is changed. Instead, using so called "conditional compilation", it is necessary to compile only those source files that have changed; for the rest, the object files are sufficient input for the linker. Finally, this makes it simple to implement libraries of pre-compiled code: just create object files and link them just like any other object file. (The fact that each file is compiled separately from information contained in other files, incidentally, is called the "separate compilation model".) To get the full benefits of condition compilation, it's probably easier to get a

description

js 05

Transcript of Question JS05 - Nur Amira Aqilah Bnti Latif

QUESTION/DISCUSION1. How toa. Compilation processThe compilation of a C++ program involves two steps:CompilationCompilationrefers to the processing of source code files (.c, .cc, or .cpp) and the creation of an 'object' file. This step doesn't create anything the user can actually run. Instead, the compiler merely produces the machine language instructions that correspond to the source code file that was compiled. For instance, if you compile (but don't link) three separate files, you will have three object files created as output, each with the name .o or .obj (the extension will depend on your compiler). Each of these files contains a translation of your source code file into a machine language file -- but you can't run them yet! You need to turn them into executables your operating system can use. That's where the linker comes in.

LinkingLinkingrefers to the creation of a single executable file from multiple object files. In this step, it is common that the linker will complain about undefined functions (commonly, main itself). During compilation, if the compiler could not find the definition for a particular function, it would just assume that the function was defined in another file. If this isn't the case, there's no way the compiler would know -- it doesn't look at the contents of more than one file at a time. The linker, on the other hand, may look at multiple files and try to find references for the functions that weren't mentioned.

You might ask why there are separate compilation and linking steps. First, it's probably easier to implement things that way. The compiler does its thing, and the linker does its thing -- by keeping the functions separate, the complexity of the program is reduced. Another (more obvious) advantage is that this allows the creation of large programs without having to redo the compilation step every time a file is changed. Instead, using so called "conditional compilation", it is necessary to compile only those source files that have changed; for the rest, the object files are sufficient input for the linker. Finally, this makes it simple to implement libraries of pre-compiled code: just create object files and link them just like any other object file. (The fact that each file is compiled separately from information contained in other files, incidentally, is called the "separate compilation model".)

To get the full benefits of condition compilation, it's probably easier to get a program to help you than to try and remember which files you've changed since you last compiled. (You could, of course, just recompile every file that has a timestamp greater than the timestamp of the corresponding object file.) If you're working with an integrated development environment (IDE) it may already take care of this for you. If you're using command line tools, there's a nifty utility calledmakethat comes with most *nix distributions. Along with conditional compilation, it has several other nice features for programming, such as allowing different compilations of your program -- for instance, if you have a version producing verbose output for debugging.

b.Execute the program#include "stdafx.h"#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[]){ unsigned int input; cout input; if(input == 1) /*execute program here*/; return 0;}

2. What is C++ ProgrammingC++(pronouncedascee plus plus,/siplspls/) is a general-purposeprogramming language. It hasimperative,object-orientedandgenericprogramming features, while also providing the facilities for low-level memory manipulation.It is designed with a bias towardsystem programming(e.g., for use inembedded systemsoroperating system kernels), with performance, efficiency and flexibility of use as its design requirements. C++ has also been found useful in many other contexts, includingdesktop applications, servers (e.g.e-commerce,web searchorSQLservers), performance-critical applications (e.g.telephone switchesorspace probes), and entertainment software.[3]C++ is acompiledlanguage, with implementations of it available on many platforms and provided by various organizations, including theFSF,LLVM,MicrosoftandIntel.C++ is standardized by theInternational Organization for Standardization(ISO), with the latest (and current) standard version ratified and published byISOin December 2014 asISO/IEC 14882:2014(informally known asC++14).[4]The C++ programming language was initially standardized in 1998 asISO/IEC 14882:1998, which was then amended by the C++03,ISO/IEC 14882:2003, standard. The current C++14 standard supersedes these andC++11, withnew featuresand an enlargedstandard library. Before the initial standardization in 1998, C++ was developed byBjarne StroustrupatBell Labs, starting in 1979, who wanted an efficient flexible language (like theC language), which also provided high-level features for program organization.Many other programming languages have been influenced by C++, includingC#,Java, and newer versions of C (after 1998).