Skip to content

Instantly share code, notes, and snippets.

@GoldsteinE
Created March 21, 2020 17:58
Show Gist options
  • Save GoldsteinE/33440b9f3f73e3de19e98ae8f99dfd64 to your computer and use it in GitHub Desktop.
Save GoldsteinE/33440b9f3f73e3de19e98ae8f99dfd64 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define IS_INT_LONG(N) _Generic((N), \
int: no_int, \
long int: yes_long, \
long long int: yes_long_long, \
default: no_no_int \
)()
void no_int() {
puts("No, it's int");
}
void yes_long() {
puts("Yes, it's long int");
}
void yes_long_long() {
puts("Yes, it's long long int");
}
void no_no_int() {
puts("It's not an int at all.");
}
int main() {
int x = 0;
long int y = 0;
long long int z = 0;
char c = 0;
IS_INT_LONG(x);
IS_INT_LONG(y);
IS_INT_LONG(z);
IS_INT_LONG(c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment