1.preprocessing
#include --->compiler 找到include的file,并复制到当前的.cpp file
#define
#ifdef
#endif
看个例子1:
EndBrace.h
}
log.cpp
#include<iostream>
void Print() {
std::cout << "Hello" << std::endl;
#include "EndBrace.h"
编译成功!
这是因为编译器把EndBrace.h中的 } 复制粘贴到了log.cpp中---》
#include<iostream>
void Print() {
std::cout << "Hello" << std::endl;
#include "EndBrace.h"
相当于
#include<iostream>
void Print() {
std::cout << "Hello" << std::endl;
}
例子2:
Math.cpp
#define INTEGER int
INTEGER Mul(INTEGER a, INTEGER b) {
return a * b;
}
看到编译文件:
Math.i --->#define
Math.i --->#if
2.编译
编译lambda.sln 后可以得到---> lambda.obj 和 log.obj
查看 .asm file
Math.asm
; Listing generated by Microsoft (R) Optimizing Compiler Version 19.16.27024.1
TITLE F:\Cherno-C++\Cherno_c++\lambdas\Math.cpp
.686P
.XMM
include listing.inc
.model flat
INCLUDELIB MSVCRTD
INCLUDELIB OLDNAMES
msvcjmc SEGMENT
__4803B6A9_math@cpp DB 01H
msvcjmc ENDS
PUBLIC ?Mul@@YAHHH@Z ; Mul
PUBLIC __JustMyCode_Default
EXTRN @__CheckForDebuggerJustMyCode@4:PROC
EXTRN __RTC_CheckEsp:PROC
EXTRN __RTC_InitBase:PROC
EXTRN __RTC_Shutdown:PROC
; COMDAT rtc$TMZ
rtc$TMZ SEGMENT
__RTC_Shutdown.rtc$TMZ DD FLAT:__RTC_Shutdown
rtc$TMZ ENDS
; COMDAT rtc$IMZ
rtc$IMZ SEGMENT
__RTC_InitBase.rtc$IMZ DD FLAT:__RTC_InitBase
rtc$IMZ ENDS
; Function compile flags: /Odt
; COMDAT __JustMyCode_Default
_TEXT SEGMENT
__JustMyCode_Default PROC ; COMDAT
push ebp
mov ebp, esp
pop ebp
ret 0
__JustMyCode_Default ENDP
_TEXT ENDS
; Function compile flags: /Odtp /RTCsu /ZI
; COMDAT ?Mul@@YAHHH@Z
_TEXT SEGMENT
_a$ = 8 ; size = 4
_b$ = 12 ; size = 4
?Mul@@YAHHH@Z PROC ; Mul, COMDAT
; File f:\cherno-c++\cherno_c++\lambdas\math.cpp
; Line 2
push ebp
mov ebp, esp
sub esp, 192 ; 000000c0H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-192]
mov ecx, 48 ; 00000030H
mov eax, -858993460 ; ccccccccH
rep stosd
mov ecx, OFFSET __4803B6A9_math@cpp
call @__CheckForDebuggerJustMyCode@4
; Line 3
mov eax, DWORD PTR _a$[ebp]
imul eax, DWORD PTR _b$[ebp]
; Line 4
pop edi
pop esi
pop ebx
add esp, 192 ; 000000c0H
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
?Mul@@YAHHH@Z ENDP ; Mul
_TEXT ENDS
END