我写了以下程序,但不包括#include <ctype.h>.我能够执行该程序.这些原型在哪里宣布?我在用gcc.
1.
#include <stdio.h>
int main()
{
if(isalnum(';'))
printf("character ; is not alphanumeric");
if(isalnum('A'))
printf("character A is alphanumeric ");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
2.
#include <stdio.h>
int main()
{
printf("Lower case of A is %c \n", tolower('A'));
printf("Lower case of 9 is %c \n", tolower('9'));
printf("Lower case of g is %c \n", tolower('g'));
printf("ASCII value of B is %d \n", toascii('B'));
printf("Upper case of g is %c \n", toupper('g'));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在您的代码中,这些函数是隐式声明的,因此它们不包含在任何特定的头文件中.如果您为编译器调高警告级别,您将看到(例如GCC):
$ gcc -Wall -o a.c
a.c: In function ‘main’:
a.c:4: warning: implicit declaration of function ‘isalnum’
Run Code Online (Sandbox Code Playgroud)
如果函数的定义不可用,则编译器假定我是一个函数,它接受任意数量的参数并返回int.例如,以下编译:
main(){fgetc(1,2,3,4,5);}
Run Code Online (Sandbox Code Playgroud)至于它们应该被声明的位置,它就是<ctype.h>标题.当然,不同的C实现可能在其他头文件中包含此标头,因此代码可能看起来没有包含<ctype.h>,但是如果您希望编译代码而不在不同的C实现中发出警告,则应该包含此标头.