[問題] 古老的函式宣告方法與用法
最近碰到一些奇怪的例子,想請教各位版上的大大幫忙解惑
以下是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)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章
14
26