我尝试使用 libconfig 设置交流程序。有example1.c:
int main()
{
const char **channel;
config_t config;
config_init(&config);
config_read_file(&config, "example.cfg");
if( config_lookup_string(&config,"value.channel",&channel) == CONFIG_FALSE)
{
printf("Failed to read fields\n");
return 1;
}
printf("argumente = %s\n", (char *)channel);
return 0;
}
和 example.cfg 文件
价值={频道=“你好”;}
如果我编译它
gcc example1.c -lconfig
它说:
example1.c:39:3: Warning: delivery of arguments 3 from »config_lookup_string« of a incompatible pointer
/usr/include/libconfig.h:244:26: Detailed: »const char **« expected, but argument has typ »const char ***«
有趣的是它有效...输出是: argumente = hello
我怎样才能摆脱这个警告?
如果我将 decleration 更改为const char *channel
和 output printf("argumente = %s\n", channel);
,我会在开始时收到段错误,并在编译时收到警告,例如...Detailed: »const char **« expected, but argument has typ »const char *«