例如,我看到像流动的源代码.我们可以#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) 这是我写的:
const int MAX=100;
int main (){
int notas [MAX]={0};
Run Code Online (Sandbox Code Playgroud)
编译器说如下:
[错误] 可能无法初始化可变大小的对象
[警告] 数组初始值设定项中的元素过多
当我用 写作MAX时#define MAX 100,它起作用了。但我不明白这样做有什么问题?