-
[cpp] cpp module 00C++(cpp) 2021. 7. 1. 18:37
string header를 include 해야하는 이유
iostream을 include하면 string header없이도 string을 사용할 수 있다.
iostream이 string header를 포함하고 있기 때문이다.
하지만 iostream에 의존해서는 안되고, 표준으로 하려면 쓰는 헤더를 다 포함해줘야 한다.
Cpp 11 안쓰기위한 컴파일 플래그
결론부터 말하자면 cpp11을 쓰는지 안쓰는지 자동으로 걸러주는 편한 플래그는 없는 것 같다. 제대로 찾아보고 알아보고 사용하는 수 밖에 없는 듯 하다.
-std=c89는 89이랑 호환이 되는지 확인하는 플래그이기 때문에 딱히 cpp11을 쓴다고 컴파일 안해주거나 하는 등의 기능이 있는 것 같지 않음.
-pendantic이라는 플래그도 사용하는 사람이 보이는데, 정확히 알고 있다는 사람이 보이지 않는다..
"The -ansi flag is equivalent to -std=c89. As noted, it turns off some extensions of GCC. Adding -pedantic turns off more extensions and generates more warnings. For example, if you have a string literal longer than 509 characters, then -pedantic warns about that because it exceeds the minimum limit required by the C89 standard. That is, every C89 compiler must accept strings of length 509; they are permitted to accept longer, but if you are being pedantic, it is not portable to use longer strings, even though a compiler is permitted to accept longer strings and, without the pedantic warnings, GCC will accept them too." [출처]
컴파일러가 c89 표준에서 더 확장해주는 것을 -pendantic을 이용하면 additional warning을 통해 금지할 수 있는 것 같다.
'C++(cpp)' 카테고리의 다른 글
[노트정리] 클래스와 클래스의 4대 속성 (0) 2021.07.15 [cpp] 상속 (0) 2021.06.24 [cpp] 디폴트 인자 (0) 2021.06.24 [cpp] 연산자 오버로딩 (0) 2021.06.24 [cpp] explicit, mutable 키워드 (0) 2021.06.24