问题
在一次开发过程中,涉及到CPP/C的混编,C部分是已经写好的,且由于各种原因无法去修改它,所以当出现了问题的时候,无法从修改源来解决,代码如下
static inline void list_add(struct list_head *new, struct list_head *head)
{
__list_add(new, head, head->next);
}
这部分代码在C中正常编译,正常使用,这是一个双向链表的节点添加,就是内核里面那套。
但是当这部分需要包含到cpp中编译时,由于new关键词,而导致编译失败,和加extern "C"没有关系
extern "C"{
#include "list.h"
}
这里开始开起来似乎无解。。。
解决
最后解决办法也比较巧妙,感谢大佬@
extern "C"{
#define new __new
#include "list.h"
#undef new
}