conversion의 설계 개념
C++의 conversion를 정의할 때, 직교하는 3 요소, value category
, cv-qualification
, data representation
를 설계 개념으로 사용한다. conversion를 설계할 때, 요소 중 하나만을 변형하고, 다른 요소를 변형하지 않는다. 어떤 이유로, 예를 들어 하위 호환성을 위해, 설계 개념을 위반할 때는 관련된 특수 조항을 스펙 문서에 별도로 명시한다.
floating-integral conversions
data representation
요소를 변형하기 위해 설계한 conversion이다. data representation
를 변경하기 때문에, conversion rank
로 분류된다. 또한 일반적으로 value category
이나 cv-qualification
를 변경하지 않는다.
floating-integral conversions
는 prvalue category
에서 prvalue category
로 변환을 정의한다.
floating-point type
의 prvalue category
는 integer type
의 prvalue category
로 변경할 수 있다. conversion 결과는 fraction part를 버리는 truncated value
다. truncated value를 목적 타입으로 표현할 수 없다면 undefined behavior
다.
integer type
이나 unscoped enumeration type
의 prvalue category
는 floating-point type
의 prvalue category
로 변경할 수 있다. 정확한 값으로 변환할 수 있다면 conversion 결과는 정확한 값이고, 근접한 두 값 사이값이면, implementation-defined에 따라 두 값 중 하나를 선택한 값이다. 표현할 수 있는 범위를 벗어난 값에 대한 conversion 결과는 undefined behavior
다. conversion 결과가 정확한 값이 아니면, 정밀도 손실이 발생한다.
목적 타입이 bool
type인 경우 boolean conversion
를 적용한다.
소스 타입이 bool
type인 경우 false
는 0, true
는 1로 변경된 후 목적 타입으로 변경될 수 있다.
'프로그래밍 언어 > C++' 카테고리의 다른 글
pointer conversions에 대해 (0) | 2024.03.02 |
---|---|
floating-point conversion에 대해 (0) | 2024.02.29 |
integral conversion에 대해 (0) | 2024.02.29 |
floating-point promotion conversion에 대해 (0) | 2024.02.28 |
integral promotion conversion에 대해 (0) | 2024.02.26 |