Created
March 5, 2016 03:59
-
-
Save koara-local/03ce0af30c9186f39b87 to your computer and use it in GitHub Desktop.
コンパイルオプションの条件次第でエラーもしくは警告を出力する ref: http://qiita.com/koara-local/items/948f9371b04b092785d1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef ERROR_DEFINED | |
#error "error macro defined" | |
#endif | |
#ifdef WARNING_DEFINED | |
#warning "warning macro defined" | |
#endif | |
int main(int argc, char const* argv[]) | |
{ | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# エラーを出力する(コンパイルを失敗として中断させる) | |
$ gcc a.cpp -DERROR_DEFINED | |
a.cpp:2:2: error: #error "error macro defined" | |
$ echo $? | |
1 | |
# 警告を出力する(コンパイルは継続する) | |
$ gcc a.cpp -DWARNING_DEFINED | |
a.cpp:6:2: warning: #warning "warning macro defined" [-Wcpp] | |
$ echo $? | |
0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment