Skip to content

Instantly share code, notes, and snippets.

@koara-local
Created March 5, 2016 03:59
Show Gist options
  • Save koara-local/03ce0af30c9186f39b87 to your computer and use it in GitHub Desktop.
Save koara-local/03ce0af30c9186f39b87 to your computer and use it in GitHub Desktop.
コンパイルオプションの条件次第でエラーもしくは警告を出力する ref: http://qiita.com/koara-local/items/948f9371b04b092785d1
#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;
}
# エラーを出力する(コンパイルを失敗として中断させる)
$ 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