3

i'm having trouble trying to define this function-like macro, which takes 4 vector magnitudes representing the major and minor axis of the top faces of a general cylinder and determines the type of general cylinder. EQUAL is an already defined macro to see if two floating point values are "equal" to one another.

3080 #define GET_TGC_TYPE(_type, _a, _b, _c, _d) { \
3081     if (EQUAL((_a), (_b)) && EQUAL((_c), (_d))) { \
3082         /* circular base and top */
3083         if (EQUAL((_a), (_c))) { \
3084             /* right circular cylinder */
3085             (_type) = RCC; \
3086         } else { \
3087             /* truncated right cone */
3088             (_type) = TRC; \
3089         } \
3090     } else { \
3091         /* elliptical base or top */
3092         if (EQUAL((_a), (_c)) && EQUAL((_b), (_d))) { \
3093             /* right elliptical cylinder */
3094             (_type) = REC; \
3095         } else { \
3096             /* truncated elliptical cone */
3097             (_type) = TEC; \
3098         } \
3099     }
3100 }

the errors i'm getting are

3083:9: error: expected identifier or ‘(’ before ‘if’
3086:11: error: expected identifier or ‘(’ before ‘else’
3090:5: error: expected identifier or ‘(’ before ‘}’ token
3090:7: error: expected identifier or ‘(’ before ‘else’
3100:1: error: expected identifier or ‘(’ before ‘}’ token

i dont have very much experience with C macros so its entirely possible i'm missing something obvious.

a3f
  • 8,517
  • 1
  • 41
  • 46
cdk
  • 6,698
  • 24
  • 51
  • 2
    As someone who has had to maintain macros like this, I politely request that you throw out this entire implementation and rewrite it as a proper C function. You can make it a static inline and stick it in a header file and it should behave exactly the same but without any of the potential macro side-effects of the current implementation. – Andrew Cottrell Jun 08 '12 at 18:27
  • @AndrewCottrell: i'm not opposed to that, could you explain some of the problems that could arise with the current macro? – cdk Jun 08 '12 at 18:32
  • 1
    @ChrisDueck: I believe your original post explains *one* of the problems that could arise with the current macro ;-) – Throwback1986 Jun 08 '12 at 18:45
  • 1
    @ChrisDueck, one example just came up [in a question today](http://stackoverflow.com/questions/10953285/evaluation-of-macro). – JoeFish Jun 08 '12 at 18:53

2 Answers2

4

Your lines with comments don't include a trailing \, so the macro definition stops at the first of them.

K-ballo
  • 80,396
  • 20
  • 159
  • 169
1

Looks like you're missing the backslashes on your comment lines.

Collin
  • 11,977
  • 2
  • 46
  • 60