作者LYSLYS (油条)
看板C_and_CPP
标题[问题] 古老的函式宣告方法与用法
时间Thu Mar 19 16:33:47 2009
最近碰到一些奇怪的例子,想请教各位版上的大大帮忙解惑
以下是source code
/* test.c */
#include <stdio.h>
/*古老的宣告函式方法*/
void bail(str, a1, a2)
char *str;
char *a1,*a2;
{
printf(str, a1, a2);
}
void bail1(char *str, char *a1, char *a2)
{
printf(str, a1, a2);
}
int main(){
bail("hello\n");//正确, why?
bail("hello %s", "world");//正确, why?
bail1("hello");//compiler-error (too few arguments)
return 0;
}
我下的指令 gcc -g -fno-stack-protector test.c && ./a.out
想请问为什麽古老的宣告方式可以用类似不定参数的方法呼叫,
而且把bail改成下面的code,也可以work,少了type也可以过,感觉很神奇
void bail(str, a1, a2)
//char *str;
//char *a1,*a2;
{
printf(str, a1, a2);
}
※ 编辑: LYSLYS 来自: 140.113.208.228 (03/19 16:34)
※ 编辑: LYSLYS 来自: 140.113.208.228 (03/19 16:35)