为什么这个多行宏不起作用?

时间:2018-02-07 10:02:29

标签: c macros

看起来它甚至没有被正确地包围。但它看起来很好。

也许它不喜欢新行?没有他们就试过了。

也许它必须是大写的?老实说,我不知道。

也许它不喜欢////评论?

#define fill(where_l, where_r, where_t, where_b, what_l, what_r, what_t, what_b) \
                                                                    \
    ////lt                                      \
    *p++ = where_l;                   \  
    *p++ = where_t;                   \
    *p++ = 0.5f;                    \
    *p++ = 1.0f;                   \
    *p++ = what_l;                   \
    *p++ = what_t;                   \
                                    \
    ////rt                   \
    *p++ = where_r;                   \
    *p++ = where_t;                   \
    *p++ = 0.5f;                   \
    *p++ = 1.0f;                   \
    *p++ = what_r;                   \
    *p++ = what_t;                   \
                   \
    ////lb                   \
    *p++ = where_l;                   \
    *p++ = where_b;                   \
    *p++ = 0.5f;                   \
    *p++ = 1.0f;                   \
    *p++ = what_l;                   \
    *p++ = what_b;                   \
                   \
    ////rb                   \
    *p++ = where_r;                   \
    *p++ = where_b;                   \
    *p++ = 0.5f;                   \
    *p++ = 1.0f;                   \
    *p++ = what_r;                   \
    *p++ = what_b;                   \

错误:

1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(573) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(573) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(573) : error C2086: 'int *p' : redefinition

完全删除评论,现在错误是:

1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(569) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(570) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(571) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(572) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(574) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(574) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(574) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(575) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(575) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(575) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(576) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(576) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(576) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(577) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(577) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(577) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(578) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(578) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(578) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(579) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(579) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(579) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(581) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(581) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(581) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(582) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(582) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(582) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(583) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(583) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(583) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(584) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(584) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(584) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(585) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(585) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(585) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(586) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(586) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(586) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(588) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(588) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(588) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(589) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(589) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(589) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(590) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(590) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(590) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(591) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(591) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(591) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(592) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(592) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(592) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(593) : error C2143: syntax error : missing ';' before '++'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(593) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(593) : error C2086: 'int *p' : redefinition
1>        c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(568) : see declaration of 'p'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(641) : error C2297: '*' : illegal, right operand has type 'float *'
1>c:\_src\directxsamples\ex_tut2_showjpg\tut2_vertices.cpp(641) : error C2017: illegal escape sequence

看起来您的帖子主要是代码,请添加更多详细信息。

以下是我如何使用它:

            float* p = (float*)malloc(999);
            fill(i_im_x, i_im_x + 512.0f,
                i_im_y, i_im_y + 512.0f,
                0.0f, 1.0f,
                0.0f, 1.0f);

1 个答案:

答案 0 :(得分:2)

你需要这样做:

  1. 将所有Clear All条评论替换为////xx
  2. 删除以下行中/* xx */之后的杂散空格字符:
  3. \

    这并不明显,因为除非你把光标放在那里,否则你看不到那个杂散空间。

    1. 删除宏最后一行中的最后*p++ = where_l; \ ^ stray space here
    2. \

      工作示例:

       *p++ = what_b;                   \
                                        ^ remove this