Last active
August 29, 2015 14:05
-
-
Save nyux/0a99a4691acf9669a898 to your computer and use it in GitHub Desktop.
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
#include <stdio.h> | |
/* does weird behavior in clang. it ignores the char* rule and casts char* | |
parameters to ints. no clue why. the uncommented version has the fix, and i'm | |
not sure why it works. | |
#define abs(x) _Generic((x), \ | |
long int: absl,\ | |
double: absd, \ | |
char*: abss, \ | |
default: absi \ | |
)(x) | |
*/ | |
#define abs(x) _Generic((0, x), \ | |
long int: absl,\ | |
double: absd, \ | |
char*: abss, \ | |
default: absi \ | |
)(x) | |
void absl(long x) { printf("this is a long: %ld\n", x); } | |
void absd(double x) { printf("this is a double: %f\n", x); } | |
void abss(char *x) { printf("no strings in absolute value funcs\n"); } | |
void absi(int x) { printf("this is an int: %d\n", x); } | |
int main(void) | |
{ | |
abs(1L); | |
abs(3.14); | |
abs("hello"); | |
abs(18); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment