最近看到两种C语言函数的写法(virant):
/* 1st virant */ int foo(int a) { return a; } /* 2nd virant */ int foo(a) int a; { return a; }
简单地说是:1st virant是C99支持的语法方式,而2nd virant (Kernighan & Ritchie) C是老的C语言建议的写法,现在越来越不被支持了。
详细见:
The "2nd dialect" is called Kernighan & Ritchie C. It is the old C defined in the late 1970s (in the very first edition of a famous book on C by Kernighan and Ritchie; subsequent editions have been conforming to later C standards). It is an obsolete language.
Current compilers are often following the C99 ISO standard (published in 1999), which has been replaced by the new C11 standard (published in 2011).
GCC compilers are accepting the C99 standard with the -std=c99
program argument. I strongly suggest to compile with gcc -Wall -std=c99
; Recent GCC compilers (ie 4.6 and 4.7) are accepting-std=c11
IIRC for the newer standard C11.
Don't code today in the old Kernighan and Ritchie C dialect: it is obsolete, and less and less supported by compilers. IMHO C99 is a good standard to follow if you are cautious. And take profit of some of its features (in particular, ability to mix declarations and statements inside a block; older C dialects required to put all the declarations at the start of a block.).