Advertisement
Guest User

Untitled

a guest
Jun 13th, 2015
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. #define OP(a,b,op) ((a)op(b))
  2.  
  3. #define MKFUNC_a_op_b(type, opname, op) void type##_##opname##_##type(const void *a, const void *b, void *out) \
  4. {\
  5.   type tmp =  OP(*(type*)a,*(type*)b,op);\
  6.   memcpy(out,(void*)(&tmp),sizeof(type));\
  7. }
  8.  
  9. #define MKALLF_int(type) \
  10. MKFUNC_a_op_b(type,plus,+) MKFUNC_a_op_b(type,minus,-) \
  11. MKFUNC_a_op_b(type,div,/) MKFUNC_a_op_b(type,mod,%) \
  12. MKFUNC_a_op_b(type,and,&) MKFUNC_a_op_b(type,or,|) \
  13. MKFUNC_a_op_b(type,xor,^)
  14.  
  15. MKALLF_int(int8_t)
  16. MKALLF_int(uint8_t)
  17. MKALLF_int(int16_t)
  18. MKALLF_int(uint16_t)
  19. MKALLF_int(int32_t)
  20. MKALLF_int(uint32_t)
  21. MKALLF_int(int64_t)
  22. MKALLF_int(uint64_t)
  23.  
  24. #define MKFUNC_conv_t(type1, type2) void type1##_to_##type2(const void *a, void *out) \
  25. {\
  26.   type2 tmp = (type2)(*(type1*)a);\
  27.   memcpy(out,(void*)(&tmp),sizeof(type2));\
  28. }
  29. #define MKFUNC_con_M(type) \
  30. MKFUNC_conv_t(type, int8_t) \
  31. MKFUNC_conv_t(type, uint8_t) \
  32. MKFUNC_conv_t(type, int16_t) \
  33. MKFUNC_conv_t(type, uint16_t) \
  34. MKFUNC_conv_t(type, int32_t) \
  35. MKFUNC_conv_t(type, uint32_t) \
  36. MKFUNC_conv_t(type, int64_t) \
  37. MKFUNC_conv_t(type, uint64_t)
  38.  
  39. MKFUNC_con_M(int8_t)
  40. MKFUNC_con_M(uint8_t)
  41. MKFUNC_con_M(int16_t)
  42. MKFUNC_con_M(uint16_t)
  43. MKFUNC_con_M(int32_t)
  44. MKFUNC_con_M(uint32_t)
  45. MKFUNC_con_M(int64_t)
  46. MKFUNC_con_M(uint64_t)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement