C++












The C++ compilation process


Compiling a source code file in C++ is a four-step process. For example, if you have a C++ source code file named prog1.cpp and you execute the compile command

   g++ -Wall -ansi -o prog1 prog1.cpp
the compilation process looks like this:

The C++ preprocessor copies the contents of the included header files into the source code file, generates macro code, and replaces symbolic constants defined using #define with their values.

The expanded source code file produced by the C++ preprocessor is compiled into the assembly language for the platform.

The assembler code generated by the compiler is assembled into the object code for the platform.

The object code file generated by the assembler is linked together with the object code files for any library functions used to produce an executable file.

By using appropriate compiler options, we can stop this process at any stage.

To stop the process after the preprocessor step, you can use the -E option:

   g++ -E prog1.cpp
The expanded source code file will be printed on standard output (the screen by default); you can redirect the output to a file if you wish. Note that the expanded source code file is often incredibly large - a 20 line source code file can easily produce an expanded file of 20,000 lines or more, depending on which header files were included.

To stop the process after the compile step, you can use the -S option:

   g++ -Wall -ansi -S prog1.cpp
By default, the assembler code for a source file named filename.cpp will be placed in a file named filename.s.

To stop the process after the assembly step, you can use the -c option:

   g++ -Wall -ansi -c prog1.cpp
By default, the assembler code for a source file named filename.cpp will be placed in a file named filename.o


EXECUTE THE PROGRAM

#include <iostream> #include <fstream> using namespace std; int main(){ ifstream inFile; inFile.open("game.exe"); if(!inFile){ cout<<"Cannot open file bish."<<endl; system("pause"); return 1; } system("pause"); }



CONCLUSION

C++ is for managed Extensions for C++ code enables the functionality of existing unmanaged code to be used in the common language runtime by clients of the managed classes. The clients can be written in any .NET Framework-compliant language, such as Managed Extensions for C++, Visual Basic, and Visual C#.Managed Extensions can also be used to directly wrap the underlying C++ class of a COM object. This can provide better performance than using the COM interface and a runtime callable wrapper because there can be less interoperability overhead and much closer control of how members are wrapped. For some COM objects, it may not be possible to use the Type Library Importer (Tlbimp.exe) to create an assembly for the COM object, and using Managed Extensions to write a custom wrapper provides a solution for this.

No comments:

Post a Comment