2014-08-27 5 views
2

함수 호출 후 매개 변수 목록을 넣는 것을 잘못 잊어 버렸습니다. 그리고 gcc가 절절한 것은 아닙니다 (왜냐하면 그는 TRUTH 값이라고 생각하기 때문입니다). 그 장소를 찾는 데 도움이되는 gcc 경고/오류 스위치가 있습니까? 예 :조건 변수를 변수로 사용하는 경고 스위치

short function(short arg); 

main() { 
    if (function) { // I wanted to write function(arg) 
    //do something 
    } 
} 

사용중인 gcc의 버전은 3.2.1입니다.

답변

3

GCC man 페이지를 보면, 필요한 것은 -Waddress 인 것 같습니다.

-Waddress 
     Warn about suspicious uses of memory addresses. These include using the address of a function in a conditional 
     expression, such as "void func(void); if (func)", and comparisons against the memory address of a string literal, such as 
     "if (x == "abc")". Such uses typically indicate a programmer error: the address of a function always evaluates to true, 
     so their use in a conditional usually indicate that the programmer forgot the parentheses in a function call; and 
     comparisons against string literals result in unspecified behavior and are not portable in C, so they usually indicate 
     that the programmer intended to use "strcmp". This warning is enabled by -Wall. 

거기에 명시된대로 -Wall과 함께이 플래그를 사용할 수 있습니다.

+0

감사합니다. gcc (Version 3.2.1)는 안타깝게도 -Waddress 기능을 제공하지 않습니다. (레거시 운영 체제의 레거시 컴파일러) –

2

gcc에서 "-Wall"옵션을 사용하십시오. 이 옵션은 gcc로 하여금 컴파일시에 모든 종류의 경고를 보여 주도록합니다.

'gcc -Wall'명령으로 코드를 컴파일 할 때 다음과 같은 경고 메시지가 나타날 수 있습니다.

함수 ''미표시 (이 기능에서 제 사용)

관련 문제