是否有独立的托管和实现之间的一个有意义的区别? [英] Is there a meaningful distinction between freestanding and hosted implementations?

查看:214
本文介绍了是否有独立的托管和实现之间的一个有意义的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要与第四节,第六段

符合标准的实现的两种形式托管和独立。一个符合托管实现应接受任何严格符合程序。

The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program.

据我了解,这构成了典型的应用环境,文件系统,分配的内存和线程...

As I understand, this constitutes the typical application environment, with filesystems, allocated memory and threads...

一个符合独立实现应接受任何严格符合程序中使用的库条款(第7章)中指定的功能仅限于标准头文件的内容< FLOAT.H> < iso646.h> < limits.h中> < stdalign.h> < STDARG.H> < stdbool.h> < STDDEF.H> < stdint.h> < stdnoreturn.h方式>

A conforming freestanding implementation shall accept any strictly conforming program in which the use of the features specified in the library clause (clause 7) is confined to the contents of the standard headers <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h>, and <stdnoreturn.h>.

...这构成了典型的内核和/或嵌入的,最低限度的环境中的的有标准的文件系统,分配的内存或线程(除其他事项外)。

... and this constitutes the typical kernel and/or embedded, bare minimum environment that doesn't have standard filesystems, allocated memory or threads (among other things).

一个符合标准的实现可以有扩展(包括附加的库函数),只要它们不改变任何严格符合程序的行为。

A conforming implementation may have extensions (including additional library functions), provided they do not alter the behavior of any strictly conforming program.

这好像这给托管实现自由自称托管或独立执行,当它涉及到文件系统,分配的内存或线程(除其他事项外),它可以只实施返回指示值的接口每一次错误。仅举几例:

It seems as though this gives a hosted implementation the freedom to call itself a hosted or freestanding implementation, and when it comes to filesystems, allocated memory or threads (among other things) it can merely implement an interface that returns a value indicating errors every time. Just to name a few:


  • 的fopen 与fgets 的malloc 可以返回 NULL

  • fprintf中的fscanf 的fputc 龟etc 可以返回 EOF

  • thrd_create 可以返回 thrd_error (表示请求不能兑现)

  • fopen, fgets and malloc can return NULL
  • fprintf, fscanf, fputc and fgetc can return EOF
  • thrd_create can return thrd_error (indicating that "the request could not be honored")

这意味着区分第四部分,第六段给出了几乎是毫无意义的。是否有保证的功能在托管和独立实现这些功能的一些实际水平什么要求吗?例如,是否需要将这些功能其实上面能够返回其它的东西比他们相应的故障值?

This implies that the distinction section four, paragraph six gives is virtually meaningless. Are there any requirements guaranteeing some actual level of functionality for these functions in hosted and freestanding implementations? For example, is it required that those functions above actually be able to return something other than their corresponding failure values?

推荐答案

引用的段落已经指出它相当不错。

The cited paragraph already states it quite well.

一个托管执行环境也是一个独立的,而不是相反。编译器只需要提供一个独立的实现。的gcc例如,严格来说是唯一的独立式,如不包括在标准库。然而,它假定编译支持托管环境(默认值)时,假设的lib可在系统(如glibc的),它是可用的。请参见这里

A hosted execution environment is also a freestanding, but not vice versa. A compiler need only provide a freestanding implementation. gcc, for example, is strictly speaking freestanding only, as the standard library is not included. However, it assumes it is available when compiling for a hosted environment (the default), assuming the lib is available on the system (like glibc). See here

简而言之,的独立的仅仅是语言。它不需要任何支持库和只有几头(多为常见的类型和执行具体的东西,如数值限制,等等)。这意味着标准库不需要存在 - 也做了相应的头文件。原因是一个独立的环境,很可能不会有这样的设施,如文件,显示等,这是用于内核,裸机嵌入式等。

Simply put, freestanding is just the language. It is not required to support any libraries and just a few headers (mostly for common types and implementation specific stuff like numerical limits, etc.). This implies the standard library need not exist - nor do the corresponding headers. Reason is a freestanding environment most likely will not have such facilities like files, display, etc. It is used for kernels, bare-metal embedded, etc.

需要注意的是GCC例如将在编译的托管环境( -fhosted ),承担标准库使用的功能有相应的意义和可能适用非常积极优化(它有许多的内置的那些功能)。对于独立的,它实际上没有,所以你可以使用函数 STRCMP 例如具有完全不同的语义。然而,它假定纪念品...-功能存在,因为这些都是用于正常$ C $℃,例如结构分配。

Note that gcc for instance will, if compiling for a hosted environment (-fhosted), assume functions used in the standard library have the corresponding meaning and might apply very aggressive optimizations (it has many of those functions built-in). For freestanding, it actually does not, so you can use a function strcmp for instance with completely different semantics. However, it assumes the mem...-functions to exist, as these are used for normal code, e.g. struct assignment.

所以,如果建设裸机,你应该总是通过 -ffreestanding

So, if building for bare-metal, you should always pass -ffreestanding.

如果一个的实施托管的调用自身的独立的,这显然不是一个的实施托管的了。一旦调用自身的托管的,但是,它必须提供标准所要求的设施和不允许只是实施假人,但有可能提供如在标准中定义的语义。

If a hosted implementation calls itself freestanding, it is obviously not a hosted implementation anymore. Once it calls itself hosted, however, it has to provide all facilities required by the standard and is not allowed to just implement dummies, but has to provide the semantics as defined in the standard.

只是国家说清楚:所引用的部分允许独立环境中省略库的所有功能,除了为数不多的上市头。所以,你可以自由地提供任何其他库,并使用相同的名称,但做任何你喜欢的。由于这将是的的标准库,没有必要遵守。

Just to state that clear: The cited section allows a freestanding environment to omit all functions of the library, except for the few listed headers. So you are free to supply any other library and use the same names, but do anything you like. As that would be not the standard library, there is no need for compliance.

5.1.2.1 进一步指出,任何库可供独立的程序,不是由第4条要求的最小集等配套设施,是实现定义。这不支持我的发言。旁注:它也不需要的main()作为程序的入口点

5.1.2.1 further states that "Any library facilities available to a freestanding program, other than the minimal set required by clause 4, are implementation-defined.". That does support my statement. Sidenote: It also does not require main() as program entry point.

这篇关于是否有独立的托管和实现之间的一个有意义的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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