Preprocessor Solution

  • + 8 comments

    I found this excercise confusing, ill-defined, unrealistic, and a waste of my time. However, following @Alexhans recommendation to solve this incrementaly is definitely the cure (short of having the answer handed to you).

    If you are still trying to figure it out, here is my recommendation:

    1. in whatever IDE (netbeans, eclipse, etc.) you are comfortable with, copy the locked code into your main file
    2. now in your IDE, comment out all "undefined" student functions in the locked code so that your main compiles correctly, even if it does absolutely nothing useful yet
    3. above the locked code that you copied into your IDE, write your #defines one at a time. As you go, uncomment the corresponding "undefined" student function, add a temporary cout << ... statement to troubleshoot your #defines or values in the main, and compile and test each #define as you go to make sure your #define's are successful and your cout statements produce what you expect.
    4. I recommend you solve your defines in this order: INF, io(), toStr(), foreach(), and FUNCTION(). In my opinion, this list is ordered from easiest to hardest.

    Short of giving you the answer or pointing you to an online resource (which you should definitely Google anyway), the biggest tip I can give: for a complex preprocessor directive like #define func(val1,val2,...,valn) <REPLACEMENT> you can put whatever you want into replacement and any call such as func(a,b,...,?) will be literally replaced with <REPLACEMENT> but on the inside of <REPLACEMENT>, val1 becomes a, val2 becomes b, ..., valn becomes ?. Also, in the <REPLACEMENT> area, #val1 becomes "a", val2##valn concatenates to b?.

    I hope this helps. Literally the worst written crash-course in preprocessor directives, so if you are frustrated, give it rest, read up on #define, work on another problem, and come back to this one later once it clicks.

    Good luck.

    P.S. oh how frustrating it is that the markdown on this site is somewhat broken. I hope you are at least somewhat able to read my comment without getting a headache.