简体   繁体   English

C 是开源的吗?

[英]Is C open source?

This is probably a stupid question, but I've been wondering about this for a while.这可能是一个愚蠢的问题,但我一直想知道这个问题有一段时间了。 Does C (or any other low-level language, for that matter) even have source, or is the compiler the part that "does all the work", including parsing? C(或任何其他低级语言,就此而言)甚至有源代码,还是编译器是“完成所有工作”的部分,包括解析? If so, couldn't different compilers have different C dialects?如果是这样,不同的编译器不能有不同的 C 方言吗? Where does the stdlib factor into this? stdlib 的因素在哪里? I would really like to know how this works.我真的很想知道这是如何工作的。

The C language is not a piece of software but a defined standard , so one wouldn't say that it's open-source, but rather that it's an open standard. C 语言不是一个软件,而是一个定义好的标准,所以不会说它是开源的,而是说它是一个开放的标准。

There are a gazillion different compilers for C however, and many of those are indeed open-source.然而,C 有无数不同的编译器,其中许多确实是开源的。 The most notable example is GCC's C compiler , which is all under the GNU General Public License (GPL) , an open-source license.最显着的例子是GCC 的 C 编译器,它都在GNU 通用公共许可证 (GPL)下,这是一个开源许可证。

There are more options.还有更多选择。 Watcom is open-source, for instance.例如,Watcom是开源的。 There is no shortage of open-source C compilers, but without a doubt the most widespread one, at least in the non-Windows world, is GCC.不乏开源 C 编译器,但毫无疑问,最广泛使用的编译器,至少在非 Windows 世界中,是 GCC。

For Windows, your best bet is probably Watcom or GCC by using Cygwin or MinGW .对于 Windows,您最好的选择可能是使用CygwinMinGW 的Watcom 或 GCC。

C is a standard which specifies how C compilers should generate programs. C 是一个标准,它指定了 C 编译器应该如何生成程序。
C itself doesn't have any source code, just like a musical note doesn't have any plastic. C 本身没有任何源代码,就像音符没有任何塑料一样。

Some C compilers, such as GCC, are open source.一些 C 编译器,例如 GCC,是开源的。

C is just a language, and a standardised one at that, too. C 只是一种语言,也是一种标准化的语言。 It pretty much is the compiler that "does all the work".几乎是“完成所有工作”的编译器。 Different compilers did have different dialects;不同的编译器确实有不同的方言; before the the C99 ANSI standard, you had things like Borland C and other competing compilers, that implemented the C language in their own fantastic ways.在 C99 ANSI 标准之前,你有像 Borland C 和其他竞争编译器这样的东西,它们以自己的奇妙方式实现了 C 语言。

stdlib is just an agreed-upon collection of standard libraries that are required to be present in any ANSI C implementation. stdlib只是一个stdlib的标准库集合,任何 ANSI C 实现中都需要这些标准库。

To add on to the other great answers:添加其他很棒的答案:

Regarding different dialects -- there are some additional features added to C that are compiler specific.关于不同的方言——C 中添加了一些特定于编译器的附加功能。 You can provide the command line flag -std=... to gcc to specify the C standard that you want to use, each has slight variations/additions to syntax, the most common is probably c99 .您可以向 gcc 提供命令行标志-std=...以指定您要使用的 C 标准,每个标准都有细微的语法变化/添加,最常见的可能是c99

Each compiler tends to implement a few different extras, for example, typeof() is not in the C standard and so compilers do not have to implement this but nevertheless it is useful and most compilers provide it.每个编译器都倾向于实现一些不同的附加功能,例如, typeof()不在 C 标准中,因此编译器不必实现它,但它仍然很有用,并且大多数编译器都提供了它。 Here is a list of gcc C extensions这是gcc C 扩展的列表

The stdlib is a set of functions specified in the C standard. stdlib 是 C 标准中指定的一组函数。 Much like compilers, stdlib can have different implementations.就像编译器一样,stdlib 可以有不同的实现。 The GNU implementation is open source, as is gcc, but there are other compilers and could be other implementations of stdlib that are closed source. GNU 实现和 gcc 一样是开源的,但还有其他编译器,并且可能是闭源的 stdlib 的其他实现。

编译器将确定从 C 到汇编等的所有映射......但就拥有它的人而言........没有人真正拥有 C 但是 ANSI/ISO 确定标准

GCC's C compiler is written in C. So we know there are at least one C compiler written in C. GCC 的 C 编译器是用 C 编写的。所以我们知道至少有一个C 编译器是用 C 编写的。

GNU's stdlib (glibc) is also written in C (stdio.h, stdlib.h). GNU 的stdlib (glibc) 也是用 C (stdio.h, stdlib.h) 编写的。 But it also has some parts written in assembly language.但它也有一些用汇编语言编写的部分。

I would say that C as a language is not open source.我会说 C 作为一种语言不是开源的。 As pointed out by many, you can download GNU licensed compilers and libraries for free, but if you wanted to write your own C compiler, you would need to follow the ISO C standards, and ISO charge hard cash for the specification of the C language, which at the time of posting this is $178.正如许多人指出的那样,您可以免费下载 GNU 许可的编译器和库,但是如果您想编写自己的 C 编译器,则需要遵循 ISO C 标准,并且 ISO 会为 C 语言的规范收取现金,在发布时为 178 美元。 So really the answer depends on what elements you are interested in being free and open source.因此,答案实际上取决于您对自由和开源感兴趣的元素。

A really good question.一个很好的问题。 There is a way to define a language standard (not the implementation!) in a form of a "source code", in a strict and unambigous language.有一种方法可以以“源代码”的形式,以严格且明确的语言定义语言标准(而不是实现!)。 Unfortunately, all of the old languages, including C, are poorly defined.不幸的是,包括 C 在内的所有旧语言都没有很好的定义。 But it is still possible to translate that definitions into a source code form.但是仍然可以将该定义转换为源代码形式。

Another approach is to define a language via its operational semantics , often in a form of a simple (and unefficient) reference implementation.另一种方法是通过其操作语义来定义语言,通常采用简单(且效率低下)的参考实现的形式。

Helgi Hrafn Gunnarsson has written the main answer but I thought it would be worth noting that you can effectively end up with dialects too. Helgi Hrafn Gunnarsson 写了主要答案,但我认为值得注意的是,您也可以有效地使用方言。

The compilers should do the same thing with regards to whichever standard they support (which these days should be pretty much all the same version) but there are grey areas.编译器应该对他们支持的任何标准做同样的事情(这些天应该几乎都是相同的版本),但存在灰色区域。 The way in which the compilers work for 'undefined' functionality for example.例如,编译器为“未定义”功能工作的方式。 If the C specification says that the behaviour is undefined for a specific case then the compiler can do pretty much what it wants.如果 C 规范说对于特定情况未定义行为,那么编译器几乎可以做它想做的事情。

There are also examples of functions added to the libraries (and new libraries added) by the compiler makers to support specific platform traits, create a competitive advantage or simply to make life easier.还有一些例子说明编译器制造商添加到库中的函数(和添加的新库)以支持特定的平台特性、创造竞争优势或只是为了让生活更轻松。 The cynical might suggest that some of these are added to help lock people into a specific compiler too.愤世嫉俗的人可能会建议添加其中一些以帮助将人们锁定在特定的编译器中。

I'm not sure what your definitions of "open source" are.我不确定您对“开源”的定义是什么。

For the standardization process, it is possible for anyone to participate, but if you want to be able to vote then you will need to pay to join your national body (for instance, ANSI for the USA, BSI for the UK, AFNOR for France etc.).对于标准化过程,任何人都可以参与,但如果您想投票,则需要付费才能加入您的国家机构(例如,美国的 ANSI、英国的 BSI、法国的 AFNOR等等。)。 As a rule most standards body memberships are paid by corporations.作为一项规则,大多数标准机构的会员资格是由公司支付的。 That said, the process is fairly open.也就是说,这个过程是相当开放的。 You can access discussion papers on the standards web site .您可以访问标准网站上的讨论文件。

The standards themselves are not free either.标准本身也不是免费的。 The ISO pdf store currently sells the C standard for 198 swiss francs . ISO pdf 商店目前以 198 瑞士法郎出售 C 标准 Draft copies of the standard can be found easily for free.可以轻松免费找到该标准的草稿副本。

There are plenty of open source implementations of both compilers and libraries.有很多编译器和库的开源实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM