CV 타입 제한자 (Const & Volatile Type Qulifiers)
컴파일러에게 특별한 제약을 부과하는 제한자이다.
각각 혼자서 사용할 수 있고, 동시에 사용될 수도 있다.
- const object
컴파일러에게 프로그램 내에서 변수의 값의 바꾸는 것을 막으라고 알린다.
사용자가 const 변수에 값을 다시 대입하면, 컴파일러는 에러를 발생시킨다.
이것은 상수를 선언하는 것과 같으며, 변수에게 non-mutable 속성을 부여하는 것 이다.
- volatile object
int flag = 0; while(flag != 1) { }; // while( true ) { };
- const volatile object
외부요인에 의해 값이 변경될 수 있지만, 프로그램 내부에서의 값 변경은 막는다.
영문으로 다음과 같이 읽힌다.
- const volatile object.
- const sub-object of volatile object.
- non-mutable volatile sub-object of const object.
변환 (Conversions)
제약이 많은 방향으로 변환될 수 있지만, 그 반대는 성립하지 않는다.
- unqulified -> const -> const volatile
- unqulified -> volatile -> const volatile
참고문서
https://en.cppreference.com/w/cpp/language/cv
cv (const and volatile) type qualifiers - cppreference.com
Appear in any type specifier, including decl-specifier-seq of declaration grammar, to specify constness or volatility of the object being declared or of the type being named. const - defines that the type is constant. volatile - defines that the type is vo
en.cppreference.com
https://showmiso.tistory.com/177
[C언어] const volatile
const - const 선언시 값을 할당할 수 있다. 선언이 끝난 const 변수는 값을 변경할 수 없다. volatile - 변수가 보통 procedure 이외에 변경될수 있는 경우에 사용한다. reload시 register나 cache가 아닌 memory..
showmiso.tistory.com
'# Lang > C++' 카테고리의 다른 글
4.1 표현식 (0) | 2019.04.10 |
---|---|
3.2 기억영역 클래스 지정자 (0) | 2019.04.06 |
2.3 자료형과 형변환 (0) | 2019.03.29 |
2.2 자료형과 데이터 해석 (0) | 2019.03.27 |
2.1 자료형 (0) | 2019.03.26 |