[問題] 古老的函式宣告方法與用法

看板C_and_CPP (C/C++)作者 (油條)時間16年前 (2009/03/19 16:33), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
最近碰到一些奇怪的例子,想請教各位版上的大大幫忙解惑 以下是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)
文章代碼(AID): #19mWDoMO (C_and_CPP)
文章代碼(AID): #19mWDoMO (C_and_CPP)