Emitting C99 or C11? #73
-
@edubart As far as I know, not many C compilers fully support C11, even today in 2021 as we speak, and even Microsoft started supporting it last year with the release of Visual Studio 2019. Do you know how many embedded devices or IoT support C11? In https://nelua.io/clibraries/ we see Nelua provides bindings for common C functions according to the C11 specification. If we didn't depend on C11 libraries exclusively, we could use another way that is already well tested. Jens Gustedt who is a C standard committee member has an excellent preprocessor library, named P99 that emulates C11 features in C99. Seems like the C libraries Nelua supports were introduced in C99 and some of them were introduced in C11; those libraries that were introduced in C11 are emulated in P99 to work as expected with C99. If you haven't researched it before, would you like to take a look? Purely out of academic curiosity and research, not more. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Nelua does not depend on C11. It does emit some C11 specific code like The C imported functions in https://nelua.io/clibraries/ are provided as convenience, and it's up to the user to choose to use it or not, in case the user does not want to depend on C11 functions just don't use C11 specific functions. For example, In the future Nelua may have some additional features using a subset of C11, like But I can't say Nelua depends only on C99, and neither C11, because the C code generator depends on some C extensions are available in most C compilers, such as: At this moment all these extensions are required to make C generated code by Nelua to compile. If the compiler does not support these extensions, then the file may not compile. These extensions are no standard C, neither C11, nor C89. However these extensions are widely available in most C compilers for a long time. For instance Clang, GCC and TCC support them. In the future I may alleviate this and make the C code generator to not depend on such extensions, but currently there is no motivation to do this, plus using these extensions make the C generated code more readable, the code generator simpler, and in some cases the generated code more efficient. I would say Nelua targets Clang/GCC/TCC, I keep close eyes to make any code compile on them with standard flags, these compilers are widely available for many of targets, including embedded devices |
Beta Was this translation helpful? Give feedback.
Nelua does not depend on C11. It does emit some C11 specific code like
_Noreturn
,_Static_assert
, but they are all used through ifdefs so the code can also compile on old compilers that don't support C11.The C imported functions in https://nelua.io/clibraries/ are provided as convenience, and it's up to the user to choose to use it or not, in case the user does not want to depend on C11 functions just don't use C11 specific functions. For example,
C.timespec_get
is only available in C11, thus you could avoid it. But note that the majority functions there are available in C99, C11 had just a few additions. The Nelua standard library does not use any C11 function and should remain this way.…