code

C에서 #error 지시어의 용도는 무엇입니까?

starcafe 2023. 6. 17. 09:32
반응형

C에서 #error 지시어의 용도는 무엇입니까?

무엇입니까?#errorC로 된 지시문?그것이 무슨 소용이 있습니까?

여러 가능성 중 하나를 예상할 때(예를 들어) 사용되는 전처리기 지시사항입니다.-D정의해야 할 기호가 없습니다.

#if defined(BUILD_TYPE_NORMAL)
# define DEBUG(x) do {;} while (0) /* paranoid-style null code */
#elif defined(BUILD_TYPE_DEBUG)
# define DEBUG(x) _debug_trace x /* e.g. DEBUG((_debug_trace args)) */
#else
# error "Please specify build type in the Makefile"
#endif

전처리기가 작동할 때#error명령어는 문자열을 오류 메시지로 보고하고 컴파일을 중지합니다. 오류 메시지가 정확히 어떻게 보이는지는 컴파일러에 따라 다릅니다.

잘못된 코드를 가지고 있을 수 있지만, 그것은 것과 같습니다.

#if defined USING_SQLITE && defined USING_MYSQL
#error You cannot use both sqlite and mysql at the same time
#endif

#if !(defined USING_SQLITE && defined USING_MYSQL)
#error You must use either sqlite or mysql
#endif


#ifdef USING_SQLITE
//...
#endif

#ifdef USING_MYSQL
//...
#endif

컴파일러가 이 행을 컴파일하면 컴파일러 치명적인 오류가 표시됩니다. 그리고 프로그램의 추가 컴파일을 중지합니다.

#include<stdio.h>
#ifndef __MATH_H
#error First include then compile
#else
int main(){
    float a,b=25;
    a=sqrt(b);
    printf("%f",a);
    return 0;
}
#endif

Output:compiler error --> Error directive :First include then compile

언급URL : https://stackoverflow.com/questions/5323349/what-is-the-use-of-the-error-directive-in-c

반응형