C语言函数的两种写法变种

最近看到两种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.).


  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值