我知道使用没有原型的函数是错误的。但是当我摆弄时,我遇到了这种奇怪而矛盾的 行为。
测试1
#include <stdio.h>
#include <limits.h>
void main(){
char c='\0';
float f=0.0;
xof(c,f);/* at this point implicit function declaration is
generated as int xof(int ,double ); */
}
int xof(char c,float f)
{
printf("%d %f\n", c,f);
}
隐式函数声明将是 int xof(int ,double );
错误是
variablename.c:8:5: error: 'xof' int xof(char c,float f) 的类型冲突
我理解这一点,因为隐式生成的函数声明(默认整数值为 INT,小数为 DOUBLE)与以下函数定义不匹配
测试2
#include <stdio.h>
#include <limits.h>
void main(){
unsigned int a =UINT_MAX;
int b=0;
xof(a); /* implicit function declaration should be int xof(int); */
}
int xof(unsigned a,int b)
{
printf("%d %d\n", a,b);
}
隐式函数声明将是 int xof(int); 应该与函数定义冲突
但这运行良好(没有错误)并且输出是'a'表现为 'int' 值并且'b'有 'undefined Garbage'
-1 12260176
有人可以解释一下吗。提前致谢。