Make an integer adder with the C preprocessor

6

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)

SoniEx2

Posted 2016-07-02T03:06:22.027

Reputation: 357

Question was closed 2016-07-02T16:48:09.797

Was is the MAX_INT and MIN_INT we have to support? – thepiercingarrow – 2016-07-02T04:50:19.660

1@Mego That challenge is not a good dupe target since it's very restrictive in input format. – James – 2016-07-02T05:30:32.787

1@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. – Mego – 2016-07-02T05:32:33.670

@PatrickRoberts The C preprocessor can't do a+b. – SoniEx2 – 2016-07-02T12:27:58.477

@Mego This one is about creating an integer adder with the C preprocessor. That one is just about summing two integers. – SoniEx2 – 2016-07-02T12:56:55.257

I'd say that this isn't a dupe. The C pre-processor is harder to program in than BF! – wizzwizz4 – 2016-07-02T15:38:37.420

3@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. – Dennis – 2016-07-02T17:58:50.370

@Dennis That challenge isn't about implementing your own integer adder in a language without an integer adder. – SoniEx2 – 2016-07-02T18:59:05.520

Sure it is. Just solve it in a language without an addition built-in. – Dennis – 2016-07-02T19:54:40.867

No, I mean this is more specific. – SoniEx2 – 2016-07-02T19:59:27.427

2The 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... – wizzwizz4 – 2016-07-03T07:13:28.187

This is not a dupe. The C preprpoceessor is really a language based on our definition it can do primality checking. @wizzwizz4 making it work for multiple integers also does seem to be a fair challenge, but its no tup to me to deem this a dupe or not – Rohan Jhunjhunwala – 2016-07-25T00:05:13.637

No answers