#include <stdio.h> #include <stdlib.h>
#define TYPE_EQUAL(n, type) \ __builtin_types_compatible_p(typeof(n), type *)
//#define PICK_OP_PRINT(op, n) \
//do { \
// if (TYPE_EQUAL((n), int)) \
// printf("int number=%d\n",*n); \
// else if (TYPE_EQUAL(n, long)) \
// printf("long number=%ld\n",*n); \
// else \
// printf("error\n"); \
//} while (0)
#define PICK_OP_PRINT(op, n) \ ({ \ if (TYPE_EQUAL((n), int)) \ printf("int number=%d\n",*n); \ else if (TYPE_EQUAL(n, long)) \ printf("long number=%ld\n",*n); \ else \ printf("error\n"); \ })
#define PICK_OP_PRINT_RET(op, n) \ ({ \ unsigned int __ret = 1; \ if (TYPE_EQUAL((n), int)) \ printf("int number=%d\n",*n); \ else if (TYPE_EQUAL(n, long)) \ printf("long number=%ld\n",*n); \ else \ printf("error\n"); \ __ret; \ })
#define printtype(n) PICK_OP_PRINT(op, n) #define printtypet(n) PICK_OP_PRINT_RET(op, n)
int main(void) { int a = 20; int ret = 0; printtype(&a); ret = printtypet(&a); printf("ret=%i\n",ret); long b = 100000000; printtype(&b); ret = printtypet(&b); printf("ret=%i\n",ret); float c = 3.6L; printf("float c=%f\n",c); printtype(&c); ret = printtypet(&c); printf("ret=%i\n",ret); return 0; }
#define PICK_OP(op, lock) \ do { \ if (TYPE_EQUAL((lock), raw_spinlock_t)) \ __spin##op((raw_spinlock_t *)(lock)); \ else if (TYPE_EQUAL(lock, spinlock_t)) \ _spin##op((spinlock_t *)(lock)); \ else __bad_spinlock_type(); \ } while (0)
//#define PICK_OP_RET(op, lock...) \
//({ \
// unsigned long __ret; \
// \
// if (TYPE_EQUAL((lock), raw_spinlock_t)) \
// __ret = __spin##op((raw_spinlock_t *)(lock)); \
// else if (TYPE_EQUAL(lock, spinlock_t)) \
// __ret = _spin##op((spinlock_t *)(lock)); \
// else __ret = __bad_spinlock_type(); \
// \
// __ret; \
//})
//
//#define PICK_OP2(op, lock, flags) \
//do { \
// if (TYPE_EQUAL((lock), raw_spinlock_t)) \
// __spin##op((raw_spinlock_t *)(lock), flags); \
// else if (TYPE_EQUAL(lock, spinlock_t)) \
// _spin##op((spinlock_t *)(lock), flags); \
// else __bad_spinlock_type(); \
//} while (0)
//
//#define PICK_OP2_RET(op, lock, flags) \
//({ \
// unsigned long __ret; \
// \
// if (TYPE_EQUAL((lock), raw_spinlock_t)) \
// __ret = __spin##op((raw_spinlock_t *)(lock), flags); \
// else if (TYPE_EQUAL(lock, spinlock_t)) \
// __ret = _spin##op((spinlock_t *)(lock), flags); \
// else __bad_spinlock_type(); \
// \
// __ret; \
//})
|