用C如何书写功能很多款式有哪些? [英] How many styles of writing functions are there in C?

查看:144
本文介绍了用C如何书写功能很多款式有哪些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我知道两种风格:

So far, I know two styles:

/* 1st style */
int foo(int a) {
return a;
}

/* 2nd style */
int foo(a)
int a;
{
return a;
}

(我看到有人在第二风格写作codeS。我很惊讶,在第一,但第二个样式的工作(下gcc作为我测试),这让我很好奇,我很想问这个问题。)

(I saw someone writing codes in the 2nd style. I was surprised at first but the 2nd style worked (under gcc as I tested). This made me curious and i wanted to ask this question.)

推荐答案

我不会把这些风格,但语言变体(或方言)。

I won't call these styles, but languages variants (or dialects).

一种编码风格是一组可能不会遵循可选约定。例如,一些编码风格要求宏名都是大写字母(但如果你不遵循这条规则您的code编译)

您2 第二风格之称的 Kernighan的&安培;里奇ç的。这是旧的C在70年代末定义(一个著名的书的第一个版本上的 C 的由Kernighan和Ritchie;后续版本已经符合后C类标准)。这是一个过时的语言。

Your "2nd style" 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.

目前的编译器往往遵循 C99 ISO标准(1999年出版),已取代了新的< A HREF =htt​​p://en.wikipedia.org/wiki/C11_%28C_standard_revision%29> C11 标准(2011年出版)。

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编译器接受与 -std = C99 程序参数C99标准。我强烈建议使用编译的gcc -Wall -std = C99 ;最近的GCC编译器(即4.6和4.7)正在接受 -std = C11 IIRC为新标准的 C11

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.

不要code的今天在老Kernighan和Ritchieç方言的:它是过时的,并且越来越被编译器支持较少。恕我直言的 C99 的是一个很好的标准,如果你是谨慎跟进。并利用它的一些特性利润(尤其是能够混个块内声明和说明;年长的 C 的把所有的声明在块的开始需要方言)。

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.).

标准的进步,特别是因为它增加的功能和更precise w.r.t.目前的制度和做法(例如多核处理器)

这篇关于用C如何书写功能很多款式有哪些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆