Skip to content

Instantly share code, notes, and snippets.

@Keith-S-Thompson
Last active August 29, 2015 14:03
Show Gist options
  • Save Keith-S-Thompson/c2dfd0ff70f8cd7850cd to your computer and use it in GitHub Desktop.
Save Keith-S-Thompson/c2dfd0ff70f8cd7850cd to your computer and use it in GitHub Desktop.
clang _Generic bug
// http://stackoverflow.com/q/24743520/827263
#include <stdio.h>
static void print_i(int i) { puts("int"); }
static void print_ip(int *i) { puts("int*"); }
#define print(num) _Generic((num), \
int : print_i(num), \
int* : print_ip(num))
int main(void) {
int i = 10;
print(i);
print(&i);
}
c.c:12:11: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'int *'; take the address with & [-Wint-conversion]
print(i);
^
&
c.c:8:23: note: expanded from macro 'print'
int* : print_ip(num))
^
c.c:4:27: note: passing argument to parameter 'i' here
static void print_ip(int *i) { puts("int*"); }
^
c.c:13:11: warning: incompatible pointer to integer conversion passing 'int *' to parameter of type 'int'; remove & [-Wint-conversion]
print(&i);
^~
c.c:7:22: note: expanded from macro 'print'
int : print_i(num), \
^
c.c:3:25: note: passing argument to parameter 'i' here
static void print_i(int i) { puts("int"); }
^
2 warnings generated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment