简体   繁体   English

遵守C \\ C ++标准有哪些责任?

[英]What responsibilities are to comply C\C++ standard?

Little bit stupid question. 有点愚蠢的问题。 For example I've read, that in C11 was added support of threads. 例如,我已经读过,在C11中增加了对线程的支持。 Then, for example GCC compiler for my STM32F4 said, that it supports C11 standard. 然后,例如我的STM32F4的GCC编译器说,它支持C11标准。 So, does it mean now, that without OS I'll achieve threading support??? 那么,现在是否意味着没有操作系统我将实现线程支持??? But how it can be? 但它怎么可能?

Another example - g++ for STM32 supports std::vectors, and IT WORKS,even without OS's memory management. 另一个例子 - 即使没有OS的内存管理,STM32的g ++也支持std :: vectors和IT WORKS。 This mean that some memory manager is inside compiler? 这意味着一些内存管理器在内部编译器? Or not? 或不?

There are two kinds of C implementations — hosted implementations, which provide the standard library, and freestanding implementations, which only need to provide the core language and a minimal number of headers. 有两种C实现 - 托管实现,提供标准库,以及独立实现,只需要提供核心语言和最少数量的头。 Implementations for embedded systems are usually freestanding. 嵌入式系统的实现通常是独立的。 This is described in detail in Section 4 of the C11 spec . 在C11规范的第4节中有详细描述。

What is more, there are a number of features that can be omitted even in a hosted implementation. 更重要的是,即使在托管实现中也可以省略许多功能。 In particular, thread support is optional (a hosted implementation that omits thread support must define the macro __STDC_NO_THREADS__ ). 特别是,线程支持是可选的(省略线程支持的托管实现必须定义宏__STDC_NO_THREADS__ )。 This is described in Section 6.10.8.3 of the spec. 这在规范的第6.10.8.3节中描述。

So, does it mean now, that without OS I'll achieve threading support??? 那么,现在是否意味着没有操作系统我将实现线程支持???

It means that the language is specified so that multi-threaded programs can be written correctly, with well-defined synchronisation when accessing shared data; 这意味着指定了语言,以便可以正确地编写多线程程序,并在访问共享数据时具有良好定义的同步; and that a full hosted implementation should provide the thread library. 并且完整的托管实现应该提供线程库。 It doesn't mean that all implementations will allow multiple threads: that will depend on support from the underlying system. 这并不意味着所有实现都允许多个线程:这将取决于底层系统的支持。

This mean that some memory manager is inside compiler? 这意味着一些内存管理器在内部编译器?

Yes, typically the language run-time includes a heap manager. 是的,通常语言运行时包括堆管理器。 It will be assigned some memory (either obtained from the OS, or allocated in some other system-dependent manner, perhaps simply as a static block when the program starts), which it then splits into smaller lumps to support dynamic allocation within the program. 它将被分配一些内存(或者从OS获得,或者以一些其他依赖于系统的方式分配,可能只是在程序启动时作为静态块),然后它分成较小的块以支持程序内的动态分配。

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

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