이름공간
변수
행위

전처리기

cppreference.com
< cpp
 
 
C++ 언어
General topics
Preprocessor
Comments
Keywords
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications(deprecated)
noexcept specifier(C++11)
Exceptions
Namespaces
Types
decltype specifier(C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier(C++11)
auto specifier(C++11)
alignas specifier(C++11)
Initialization
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration(C++11)
attributes(C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs(C++11)
Miscellaneous
Inline assembly
 
 

전처리기는 컴파일이 시작되기 전에 작동됩니다. 전처리의 결과는 파일 하나로 만들어져 컴파일러에게 전달됩니다.

[편집]지시어

전처리 지시어는 전처리기가 어떻게 작동될지를 결정합니다. 전처리 지시어는 한 줄로 이루어져 다음과 같은 형식을 따릅니다:

  • # 문자
  • 전처리 명령어 (define, undef, include, if, ifdef, ifndef, else, elif, endif, line, error, warning, {{tt|pragma} 중 하나) [1]
  • 인자들 (명령어에 따라)
  • 줄바꿈

빈 지시어 (줄바꿈 다음에 있는 #) 는 허용되고 아무 기능도 하지 않습니다.

[편집]호환성

전처리기는 소스 파일 번역 호환성이 있습니다:

  • 소스파일의 일부를 조건적으로 컴파일 (#if, #ifdef, #ifndef, #else, #elif, #endif 지시어로 사용).
  • 식별자를 합치거나(concatenate) 참조할 수 있을 경우 텍스트 매크로를 치환 (#define, #undef 지시어와 연산자 #, ## 로 사용)
  • 다른 파일을 인클루드 (#include 지시어로 사용)
  • 경고를 일으킴 (#warning 지시어로 사용)
  • 에러를 일으킴 (#error 지시어로 사용)

전처리기의 다음과 같은 특성들을 조절 가능:

[편집]Footnotes

  1. 이 명령어들은 표준에 의해 정의된 지시어입니다. 표준은 다른 지시어의 동작에 대해 정의하지 않습니다 (무시될수도 있고, 특별한 기능을 수행할 수도 있으며, 프로그램을 안 좋은 형태로 바꾸기도 합니다.)
close