0% found this document useful (0 votes)
58 views

01 - How C++ Works

C++ code is compiled into machine code for the target platform. A C++ project contains source code files that are compiled individually into object files, then linked together into an executable binary. The compilation process involves preprocessing, compiling, and linking. Preprocessing involves including header files. Compiling transforms code into machine code. Linking resolves external references by connecting function declarations to definitions between object files to produce a final executable.

Uploaded by

22194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

01 - How C++ Works

C++ code is compiled into machine code for the target platform. A C++ project contains source code files that are compiled individually into object files, then linked together into an executable binary. The compilation process involves preprocessing, compiling, and linking. Preprocessing involves including header files. Compiling transforms code into machine code. Linking resolves external references by connecting function declarations to definitions between object files to produce a final executable.

Uploaded by

22194
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

01_how c++ works

• solution
– group of projects related to each other
• various project types
– work bench
– each project
• group of files
• complies intro a target binary
– library
– executable
# include <iostream>

intro
• direct control over hardware
• pass code into compiler
– output machine code for target-platform
• instructions that cpu perform
• wide platform support
• c# of java run on a virtual machine
– code gets compiled into an intermediate language first
– buy an english book
• with a translator
• native languages like c++
– translate the book in english
– compiler produces machine code for that target platform and architecture
– no translation requires
– just push cpu intructions into cpu
• from source to executable
– source
– binary executable (program of binary)

executable binaries
• preproccessor statements
– look at the file “iostream”
– take its contents and paste then into the file
– called header files
– iostream
• declaration for function cout
– print stuff onto console
• main function
– called th eentry point
– starts executing code inside this function
– in the order
– dependent on control flow statement = calls to other functions
– code gets executed line by line
• return type for main in “int”
– but the main function is a special case
– you don’t return any kind of value from main function
• it will assume that you’re returning 0
• [only applies to main function]
• int main()
• {
– std::cout << “fuck my life” << std::endl;
– std:: cin.get();
– return 0;
• }

• <<-operator
– think of it as a function
– operators are functions
– << = print
– “Hello world” = parameter
– fuck is a paramenter
• push the hello string into cout
• push the endl
• std:: cin.get();
– waits for us to enter someting
• stages
• preproccessor gets evaluated
– includes contents of iostream file into this file
drop-down menus
• compiler transforms code into machine code

– solution configurations
• debug
• release
– optimizatons is turned on
– solution platform
• x86
• win32
• configuration

– set of [rules] that applies to the building of a project


– defines the compilation for that platform
– configuration type
• appplication
• library
• solution platform

– what platform is targeted with our targeted compilation


– x86-targets windows x32
– build/deploy/debug on android->platform wpuld be android
• cpp file gets compiled
• header filed do not get compiled

• [rules we can change]

– properties
– define rules used to build certain configuration and platrofms
– configuratyion type
• type of binary created
– application = executable binary
• configuration and platform area

– active(debug)
– win32=x86
• optimization debug vs release

– release = max speed


– debut - disabled

• obj file
– in the debug folder
• exe file
– in the solution directory
• debug folder

• compiler
– cpp files
– compiled individual
• individual obj files
– compiled into an object file-stitched-by linker
• linker
– takes obj files
– glues them
• compile files individually
– ctrl+f7
• build files into the debug folder
– obj
– pdb
• if building the entire project
– transforms into exe

• declarations
– statements that say that smth exists
• definition
– this is what it is
– the body of a functions
• [how does the compiler knows we have the right file]
• linker
– find the definition of that log function
– wires it to the Log function in the main file
– alternatively there is a [linker error]
• function’s signature details
– calling convention
• "void **__cdecl** Log(char const *)"
– parameter: const char pointer
– actual ID
• (?Log@@YAXPBD@Z) referenced in function _main
• unresolved external symbol called log
– return value
• void
– these parameter
• char const *
– referenced in main
– linker unable to resolve a signal
["void __cdecl Log(char const *)"(?Log@@YAXPBD@Z) referenced in function _main]
• debug
– 2 obj files
• common binary
– debug
• exe

You might also like