【发布时间】:2015-08-24 08:58:36
【问题描述】:
函数 stricmp() 和 strnicmp() 在 C99 中被删除了吗?
当我尝试针对 C99 编译它时,我总是收到警告 implicit declaration of function stricmp() (以及 strnicmp() )。
例如,下面的简单代码让我收到警告。
#include<string.h>
#include<stdio.h>
char arr[100]="hello";
char arr2[100]="hEllo";
int main()
{
int n=-1;
printf("%d\n",n);
n=strnicmp(arr,arr2,3); // the same when use the function stricmp();
printf("%d\n",n);
getchar();
return 0;
}
当我尝试针对 C99(gcc -Wall -std=c99 main.c -o main) 编译这段代码时,我收到了警告。但是当我在没有-std=c99 的情况下编译它时,不会抛出任何警告。
但是,即使有隐式声明的警告,我的代码仍然可以正常工作。
这是为什么呢?那是一个错误吗?如果不是错误,那么导致该警告发生的 C99 的更改究竟是什么?
【问题讨论】:
-
那些函数从未出现在 C 标准中,实际上 C 标准中没有不区分大小写的字符串比较函数。
stricmp、strcasecmp等函数都是其他标准(POSIX、WINdows等)的扩展或定义