Skip to content

Instantly share code, notes, and snippets.

@johnmcfarlane
Created August 28, 2018 12:42
Show Gist options
  • Save johnmcfarlane/df4061be9d7c803204f99d72ca624101 to your computer and use it in GitHub Desktop.
Save johnmcfarlane/df4061be9d7c803204f99d72ca624101 to your computer and use it in GitHub Desktop.
code to test warning level of C++ translation unit
// code to test warning level of C++ translation unit;
// works with compilers which support `-Wpedantic` flag
// any warning level: 'extern' variable has an initializer [-Wextern-initializer]
// -Wall: "unused variable 'n' [-Wunused-variable]"
// -Wextra: "missing field 'b' initializer [-Wmissing-field-initializers]"
extern struct { int a, b; } n = {sizeof(void(*)(int))};
// -Wpedantic: "variable length arrays are a C99 feature [-Wvla-extension]"
int evoke_pedantic_warning_vla(int n) { int a[n]; return a[3]; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment