C++ - DO-WHILE에 의한 매크로 트랩핑

출처 #ifdef _DEBUG #define DEBUG_LOG(exp, ...) do {if (!(exp)){std::printf(__VA_ARGS__);}} while(0) #else #define DEBUG_LOG(exp, ...) do {(void)(exp);} while(0) #endif int main() { int x = 99; DEBUG_LOG(x > 100,"warning! x = %d", x); // x가 100 이하라면 경고를 표시 return 0;...
더 읽기

C++ - 문자열을 수치로 변환하는 방법

atoi #include <cstdlib> #include <iostream> #include <string> #include <typeinfo> int main() { const std::string str("123"); auto num = std::atoi(str.c_str()); std::cout << typeid(num).name() << " : " << num << std::endl; } strtol #include <cstdlib> #include <iostream> #include <string> #include <typeinfo>...
더 읽기

C++ - 표준 attribute 정리

원문 attribute(속성) 라는 것은 attribute(속성)는 컴파일러에 추가 정보를 전달하는 구문으로 [[attributes]] 이라고 쓴다. 최적화나 경고 추가나 제어 등을 할 수 있다. C++11 noreturn 속성 함수 함수가 결코 반환 하지 않는 것을 표시하는 속성 예외 송출이나 std::exit, std::abort 의 랩퍼 함수에...
더 읽기