Skip to content

Instantly share code, notes, and snippets.

@sighingnow
Created April 26, 2018 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sighingnow/2206245998aa2f769b4470305447a563 to your computer and use it in GitHub Desktop.
Save sighingnow/2206245998aa2f769b4470305447a563 to your computer and use it in GitHub Desktop.
ghc treat certain kinds of warnings as errors when compile c source file.
D:\Open>gcc test.c -Wall -c
test.c: In function 'g':
test.c:8:14: warning: passing argument 1 of 'f' from incompatible pointer type [-Wincompatible-pointer-types]
return f(cp);
^~
test.c:1:5: note: expected 'int *' but argument is of type 'char *'
int f(int *a) {
^
D:\Open>stack exec -- ghc -c test.c -Wall
test.c: In function 'g':
test.c:8:14: error:
warning: passing argument 1 of 'f' from incompatible pointer type [-Wincompatible-pointer-types]
return f(cp);
^~
|
8 | return f(cp);
| ^
test.c:1:5: error:
note: expected 'int *' but argument is of type 'char *'
int f(int *a) {
^
|
1 | int f(int *a) {
| ^
int f(int *a) {
return 1;
}
int g() {
char c = 'a';
char *cp = &c;
return f(cp);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment