매크로에서 확장 된 코드에서 g ++ 경고를 사용하지 않으려합니다. 나의 이해함으로써, _Pragma
매크로 사용을 따라야하고 g++
컴파일 될 때이 Wparentheses
실행되지 않습니다 :G ++ 무시 _Pragma 진단
#include <stdio.h>
#define TEST(expr) \
int a = 1; \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wparentheses\"") \
if (a <= expr) { \
printf("filler\n"); \
} \
_Pragma("GCC diagnostic pop")
int main(){
int b = 2, c = 3;
TEST(b == c);
}
내가 g++
로이를 컴파일 할 때, 내가 사용하지 않도록 노력하고 Wparentheses
경고를 얻을. 예상대로 gcc
를 사용하는 경우
[email protected]:/mnt/c/ubuntu$ g++ -Wall -Wextra test3.c
test3.c: In function ‘int main()’:
test3.c:8:11: warning: suggest parentheses around comparison in operand of ‘==’ [-Wparentheses]
if (a <= expr) { \
^
test3.c:15:5: note: in expansion of macro ‘TEST’
TEST(b == c);
^
그러나 그것은 작동 : 나는 g++
버전 4.8.5을 사용하고
[email protected]:/mnt/c/ubuntu$ gcc -Wall -Wextra test3.c
test3.c: In function ‘main’:
test3.c:16:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
.
gcc 4.8.5는 게시 된 소스 코드를'gcc -Wall -Wextra test3.c'로 컴파일하지 않습니다. iostream은 C 헤더 파일이 아니기 때문에'fatal error : iostream : No such file or directory' 명령으로 실패합니다. 실제 코드를 게시하십시오. –
@MikeKinghan 죄송합니다. 질문을 자극 한 .cpp 파일에서 붙여 넣습니다. 이제'printf'를 사용합니다. – Xarn