简体   繁体   中英

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. Then, for example GCC compiler for my STM32F4 said, that it supports C11 standard. 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. 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. Implementations for embedded systems are usually freestanding. This is described in detail in Section 4 of the C11 spec .

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__ ). This is described in Section 6.10.8.3 of the spec.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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