HWND
HINSTANCE
LPCWSTR
LRESULT
아스키, 유니코드, utf8, utf16차이점, 언리얼 텍스트 매크로는 뭐냐
솔직히 왜쓰는지 제대로 이해도 안가고 잘 몰랐는데 확실히 공부해야겠다고 생각해서 찾아봄
일반함수는 컴파일 후 개념적으로
result = Add(1, 2); // Add함수의 기계어 주소로 점프(call)
Add의 구현은 다른 .cpp에 있어도, 컴파일,링크 과정에서 함수의 기계어 주소가 연결된다. CPU는 파일을 찾는게 아니라 해당 주소로 바로 점프
인라인 함수는 구현을 헤더에 두어 호출하는 .cpp가 컴파일시 함수 본문을 볼 수 있게 한다. 그러면 컴파일러가
result = Add(1, 2);
// 위를 다음과 같이 판단한다.
result = 1 + 2;
Add함수로가서 계산하고 호출하는쪽으로 오는게 아니라, 함수 호출자리에 함수 본문을 직접 삽입하는 식으로 계산됨
C++에서 h와 cpp는 컴파일 단계를 알아보자
// Math.h
int Add(int a, int b)
// Math.cpp
#include "Math.h"
int Add(int a, int b){
return a + b;
}
// Main.cpp
#include "Math.h"
int main(){
return Add(1, 2);
}
#include "Math.h"는 해당 헤더 내용을 코드에 그대로 붙여넣는것 처럼 처리된다.int Add(int a, int b)
int main(){
return Add(1, 2);
}
Math.cpp도 마찬가지로 헤더 선언을 포함한 상태에서 컴파일 된다.
각 .cpp파일은 서로 독립적으로 컴파일 된다.
이 결과가 각각의 .obj 목적파일이 된다.
링커가 Main.obj와 Math.obj를 합침
링커가 둘을 연결해 최종실행파일을 만듬
실행할때는 .h나 .cpp파일을 읽지 않음. 최종 실행파일안에 이미 Add의 기계어 코드와 그 위치 정보가 들어있다.
// Math.h
inline int Add(int a, int b){
return a + b;
}
인라인 함수는 이런식으로 헤더에 구현을 둔다. 그러면 Main.cpp를 컴파일할때 Add의 구현도 보이므로 컴파일러가 호출위치에 a+b 계산 코드를 직접 넣는 인라인 최적화를 할 수 있다.
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cctype>
using namespace std;
int solution(int cacheSize, vector<string> cities) {
int answer = 0;
list<string> cache;
if (cacheSize == 0) return cities.size() * 5;
for (string& city : cities){
transform(city.begin(), city.end(), city.begin(), ::tolower);
auto it = find(cache.begin(), cache.end(), city);
if (it != cache.end()){
answer++;
cache.erase(it);
cache.push_front(city);
} else {
answer+=5;
if ((int)cache.size() == cacheSize){
cache.pop_back();
}
cache.push_front(city);
}
}
return answer;
}