相关疑难解决方法(0)

是否可以在函数内使用#define?

例如,我看到像流动的源代码.我们可以#define在一个函数中使用吗?它是如何工作的?(更多信息:这些代码是我从openvswitch源代码中复制的代码):

void *
ofputil_put_action(enum ofputil_action_code code, struct ofpbuf *buf)
{
switch (code) {
case OFPUTIL_ACTION_INVALID:

#define OFPAT13_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME) case OFPUTIL_##ENUM:
#include "ofp-util.def"
    OVS_NOT_REACHED();

#define OFPAT10_ACTION(ENUM, STRUCT, NAME)                  \
case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf);
#define OFPAT11_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)      \
case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf);
#define NXAST_ACTION(ENUM, STRUCT, EXTENSIBLE, NAME)        \
case OFPUTIL_##ENUM: return ofputil_put_##ENUM(buf);
#include "ofp-util.def"
}
OVS_NOT_REACHED();
}

#define OFPAT10_ACTION(ENUM, STRUCT, NAME)                        \
void                                                        \
ofputil_init_##ENUM(struct STRUCT *s)                       \
{                                                           \
    memset(s, 0, sizeof *s); …
Run Code Online (Sandbox Code Playgroud)

c c++

16
推荐指数
3
解决办法
1万
查看次数

简单但特定的数组编译错误(C)

这是我写的:

   const int MAX=100;

   int main (){
       int notas [MAX]={0};
Run Code Online (Sandbox Code Playgroud)

编译器说如下:

[错误] 可能无法初始化可变大小的对象
[警告] 数组初始值设定项中的元素过多

当我用 写作MAX#define MAX 100,它起作用了。但我不明白这样做有什么问题?

c arrays initialization declaration variable-length-array

2
推荐指数
1
解决办法
73
查看次数