fork(1) download
  1. #include <stdio.h>
  2.  
  3. #define BASE 2
  4. #define NUM_DIGITS 8
  5. #define SEPARATOR "_"
  6.  
  7. #define PP_JOIN_REPEAT(str, separator, n) PP_JOIN_REPEAT_IMPL(str, separator, n)
  8. #define PP_JOIN_REPEAT_IMPL(str, separator, n) PP_JOIN_REPEAT_##n( str, separator)
  9. #define PP_JOIN_REPEAT_1( str, separator) str
  10. #define PP_JOIN_REPEAT_2( str, separator) PP_JOIN_REPEAT_1(str, separator) separator str
  11. #define PP_JOIN_REPEAT_3( str, separator) PP_JOIN_REPEAT_2(str, separator) separator str
  12. #define PP_JOIN_REPEAT_4( str, separator) PP_JOIN_REPEAT_3(str, separator) separator str
  13. #define PP_JOIN_REPEAT_5( str, separator) PP_JOIN_REPEAT_4(str, separator) separator str
  14. #define PP_JOIN_REPEAT_6( str, separator) PP_JOIN_REPEAT_5(str, separator) separator str
  15. #define PP_JOIN_REPEAT_7( str, separator) PP_JOIN_REPEAT_6(str, separator) separator str
  16. #define PP_JOIN_REPEAT_8( str, separator) PP_JOIN_REPEAT_7(str, separator) separator str
  17. #define PP_JOIN_REPEAT_9( str, separator) PP_JOIN_REPEAT_8(str, separator) separator str
  18. #define PP_JOIN_REPEAT_10(str, separator) PP_JOIN_REPEAT_9(str, separator) separator str
  19.  
  20. #define PP_POW(base, exp) PP_POW_IMPL( base, exp)
  21. #define PP_POW_IMPL(base, exp) PP_POW_##exp(base)
  22. #define PP_POW_0(base) (1)
  23. #define PP_POW_1(base) (PP_POW_0(base) * (base))
  24. #define PP_POW_2(base) (PP_POW_1(base) * (base))
  25. #define PP_POW_3(base) (PP_POW_2(base) * (base))
  26. #define PP_POW_4(base) (PP_POW_3(base) * (base))
  27. #define PP_POW_5(base) (PP_POW_4(base) * (base))
  28. #define PP_POW_6(base) (PP_POW_5(base) * (base))
  29. #define PP_POW_7(base) (PP_POW_6(base) * (base))
  30. #define PP_POW_8(base) (PP_POW_7(base) * (base))
  31. #define PP_POW_9(base) (PP_POW_8(base) * (base))
  32.  
  33. #define PP_GET_DIGIT_AT(index, value, base) PP_GET_DIGIT_AT_IMPL(index, value, base)
  34. #define PP_GET_DIGIT_AT_IMPL(index, value, base) PP_GET_DIGIT_AT_##index(value, base)
  35. #define PP_GET_DIGIT_AT_0(value, base) (((value) / PP_POW(base, 0)) % (base))
  36. #define PP_GET_DIGIT_AT_1(value, base) (((value) / PP_POW(base, 1)) % (base))
  37. #define PP_GET_DIGIT_AT_2(value, base) (((value) / PP_POW(base, 2)) % (base))
  38. #define PP_GET_DIGIT_AT_3(value, base) (((value) / PP_POW(base, 3)) % (base))
  39. #define PP_GET_DIGIT_AT_4(value, base) (((value) / PP_POW(base, 4)) % (base))
  40. #define PP_GET_DIGIT_AT_5(value, base) (((value) / PP_POW(base, 5)) % (base))
  41. #define PP_GET_DIGIT_AT_6(value, base) (((value) / PP_POW(base, 6)) % (base))
  42. #define PP_GET_DIGIT_AT_7(value, base) (((value) / PP_POW(base, 7)) % (base))
  43. #define PP_GET_DIGIT_AT_8(value, base) (((value) / PP_POW(base, 8)) % (base))
  44. #define PP_GET_DIGIT_AT_9(value, base) (((value) / PP_POW(base, 9)) % (base))
  45.  
  46. #define PP_EXPAND_DIGITS(value, base, digits) PP_EXPAND_DIGITS_IMPL(value, base, digits)
  47. #define PP_EXPAND_DIGITS_IMPL(value, base, digits) PP_EXPAND_DIGITS_##digits(value, base)
  48. #define PP_EXPAND_DIGITS_1( value, base) PP_GET_DIGIT_AT(0, value, base)
  49. #define PP_EXPAND_DIGITS_2( value, base) PP_GET_DIGIT_AT(1, value, base), PP_EXPAND_DIGITS_1(value, base)
  50. #define PP_EXPAND_DIGITS_3( value, base) PP_GET_DIGIT_AT(2, value, base), PP_EXPAND_DIGITS_2(value, base)
  51. #define PP_EXPAND_DIGITS_4( value, base) PP_GET_DIGIT_AT(3, value, base), PP_EXPAND_DIGITS_3(value, base)
  52. #define PP_EXPAND_DIGITS_5( value, base) PP_GET_DIGIT_AT(4, value, base), PP_EXPAND_DIGITS_4(value, base)
  53. #define PP_EXPAND_DIGITS_6( value, base) PP_GET_DIGIT_AT(5, value, base), PP_EXPAND_DIGITS_5(value, base)
  54. #define PP_EXPAND_DIGITS_7( value, base) PP_GET_DIGIT_AT(6, value, base), PP_EXPAND_DIGITS_6(value, base)
  55. #define PP_EXPAND_DIGITS_8( value, base) PP_GET_DIGIT_AT(7, value, base), PP_EXPAND_DIGITS_7(value, base)
  56. #define PP_EXPAND_DIGITS_9( value, base) PP_GET_DIGIT_AT(8, value, base), PP_EXPAND_DIGITS_8(value, base)
  57. #define PP_EXPAND_DIGITS_10(value, base) PP_GET_DIGIT_AT(9, value, base), PP_EXPAND_DIGITS_9(value, base)
  58.  
  59. int main() {
  60. PP_JOIN_REPEAT("%d", SEPARATOR, NUM_DIGITS),
  61. PP_EXPAND_DIGITS(134, BASE, NUM_DIGITS)
  62. );
  63. }
  64.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
1_0_0_0_0_1_1_0