在C ++中包含C时出错

时间:2014-08-30 22:17:15

标签: c++

我试图在C ++代码中包含C代码" config.h",使用:

extern "C"
{
#include "config.h"
}

如果我编译" config.h"与gcc分开我没有错误,但是当我使用g ++编译C ++代码时,我收到以下错误:

从'void '无效转换为'char *'*

错误指向" config.h":

中的以下行
newsect->name = malloc(strlen(config));

其中config的类型为char *。

任何人都可以告诉我如何使这项工作?提前谢谢!

1 个答案:

答案 0 :(得分:0)

name可能是char *,所以只需使用:

newsect->name = (char *)malloc(strlen(config));

希望这有帮助!

相关问题