我在尝试定义此函数式宏时遇到问题,它使用4个矢量量值来表示一般圆柱体顶面的主轴和副轴,并确定一般汽缸的类型。EQUAL是已定义的宏,以查看是否两个浮点值是“相等”到彼此。错误:预期标识符或'('之前,宏定义
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 }
我发现了错误是
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
我不对C宏有非常丰富的经验,所以完全有可能我是mi选择明显的东西。
是'EQUAL'宏吗? – qwertz
作为一个必须像这样维护宏的人,我礼貌地要求你抛出这个完整的实现并将其重写为一个合适的C函数。您可以将其设置为静态内联并将其粘贴到头文件中,并且其行为应该完全相同,但是没有任何当前实现的潜在宏观副作用。 –
@AndrewCottrell:我不反对,你能解释一下当前宏可能出现的一些问题吗? – cdk