What responsibilities should the C \ C ++ standard comply with?

A bit silly question. For example, I read that thread support was added in C11. Then, for example, the GCC compiler for my STM32F4 said it supports the C11 standard. So, does this mean that without an OS, I can achieve threading support? But how can this be?

Another example is g ++ for STM32 supports std :: vectors, and IT WORKS, even without OS memory management. Does this mean that some memory manager is inside the compiler? Or not?

+3


source to share


2 answers


So, does this mean that without the OS, I get thread support?

This means that the language is specified so that multithreaded programs can be written correctly, with well-defined synchronization when accessing shared data; and that the full hosted implementation should provide a threading library. This does not mean that all implementations will allow multiple threads: it will depend on the support of the underlying system.



Does this mean that some memory manager is inside the compiler?

Yes, usually the language runtime includes a heap manager. It will be assigned some memory (either received from the OS, or allocated in some other system-dependent way, perhaps just as a static block when the program starts), which is then split into smaller chunks to support dynamic allocation within the program.

+2


source


There are two kinds of C implementations — hosted implementations, which provide the standard library, and stand-alone implementations, which should only provide the host language and a minimum amount of headers. Embedded systems implementations are usually self-contained. This is detailed in section 4 of the C11 specification .



In addition, there are a number of functions that can be omitted even in a hosted implementation. In particular, thread support is optional (a hosted implementation that omits thread support must define a macro __STDC_NO_THREADS__

). This is described in section 6.10.8.3 of the specification.

+7


source







All Articles