The C preprocessor is not turing-complete, but you can do some pretty cool stuff with it.

The challenge is to make an integer adder with it. You can use any representation you like: base 2, base 10, unary, separate each digit with a comma, etc. Whatever you do, you may only use the C preprocessor.

The rules are simple:

  • You can only use the C preprocessor.
  • You must support both positive and negative integers.
  • You can use any integer representation you like, both for input and output. You must clearly state what representation(s) you're using. The input representation doesn't have to match the output representation.
  • CRLF counts as 2 bytes, LF counts as 1. Convert your files to LF line endings.
  • You must actually calculate the values, that is, they should neither be hardcoded nor output as a+b. This is a C preprocessor challenge, not a C challenge.
  • You must have an ADD macro that takes two numbers and outputs one. The numbers must be comma-separated. (for example ADD(a1,a2,a3,...,a32,b1,b2,b3,...,b32) for 32-bit fixed-width binary input.)

Possible inputs and their outputs, in decimal:

  • 133, 57 (= 190)
  • 123, 321 (= 444)
  • 111, 289 (= 400)
  • 9, 9 (= 18)
  • 18, 18 (= 36)
  • 9, -9 (= 0)
  • -9, -9 (= -18)
  • 0, 9 (= 9)
  • -9, 0 (= -9)
  • 399, -400 (= -1)
  • \$\begingroup\$ Was is the MAX_INT and MIN_INT we have to support? \$\endgroup\$ – thepiercingarrow Jul 2 '16 at 4:50
  • 1
    \$\begingroup\$ @Mego That challenge is not a good dupe target since it's very restrictive in input format. \$\endgroup\$ – James Jul 2 '16 at 5:30
  • 1
    \$\begingroup\$ @DrGreenEggsandIronMan The input format is actually very relaxed from its original incarnation. It's still a bit stricter than usual for challenges, but not by much. This is a dupe because it's the exact same challenge, but with a very tight language restriction. Answers here could be posted in that challenge and be competitive. \$\endgroup\$ – user45941 Jul 2 '16 at 5:32
  • 3
    \$\begingroup\$ @wizzwizz4 That doesn't matter. Addition is addition. We don't need integer adder in C preprocessor, integer adder in Malbolge, integer adder in Seed, etc. as different challenges. \$\endgroup\$ – Dennis Jul 2 '16 at 17:58
  • 2
    \$\begingroup\$ The C pre-processor is hard to program in because it isn't a programming language. It is a tool that people use to aid them in their C compiling, but it definitely isn't a programming language; it's not even Turing complete! *sigh* But I suppose we could just put C pre-processor answers on that question... \$\endgroup\$ – wizzwizz4 Jul 3 '16 at 7:13

Browse other questions tagged or ask your own question.