这是我的代码:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
static int valid_line(char *cur_line) {
if (*cur_line == '#') {
return 0;
}
char *end = strchrnul(cur_line, '#');
while(end > cur_line && isspace(*end)) end--;
return (!(*cur_line == *end));
}我正在检查这行代码,去掉了前导空格和尾随空格以及“#”(包括“#”)之后出现的任何空格。
我的编译器是这样说的:
parser.c:20:2: warning: implicit declaration of function ‘strchrnul’ [-Wimplicit- function-declaration]
parser.c:20:14: warning: initialisation makes pointer from integer without a cast [enabled by default]虽然我在上面有string.h,但我还是使用了EVen。
有人能解释一下吗。
发布于 2013-06-04 02:53:23
strchrnul()是一个GNU扩展,你可以通过一个feature test macro获得这个函数的免费警告。
#define _GNU_SOURCE // required for strchrnul()
#include <stdio.h>
#include <ctype.h>
#include <string.h> // required for strchrnul()
#include <stdlib.h>
static int valid_line(char *cur_line) {
if (*cur_line == '#') {
return 0;
}
char *end = strchrnul(cur_line, '#');
while(end > cur_line && isspace(*end)) end--;
return (!(*cur_line == *end));
}请注意,在第二个链接的手册页中,#define的位置很重要:
注意:为了有效,必须在包含任何头文件
之前定义功能测试宏
发布于 2013-06-04 02:26:36
如果您使用的是gcc编译器,请不要使用-std=c89或-std=c99,而要使用-std=gnu89或-std=gnu99,因为strchrnul是一个GNU扩展。
https://stackoverflow.com/questions/16903285
复制相似问题