nim-lang / RFCs

A repository for your Nim proposals.
136 stars 26 forks source link

C89 compiler support #488

Closed sls1005 closed 2 years ago

sls1005 commented 2 years ago

Abstract

Add a new option --cc:c89, with which Nim generates C code that follows the C89 specification, so that it can be compiled with any C compiler (that is compatible with the ANSI specification) chosen by the user.

Motivation

Nim was designed to be running on every platform with a C compiler. However, it can only be use with the supported compilers, and if you are using --passC:"-std=c89", you get an error because inline was not defined. But if it follows the C standards, then it'll be able to be compiled with any valid C compiler.

Description

With this option specified, the compiler must not use something like __inline or inline, as they're against the C89 specification.

The users of this option must specify --c89.exe, --c89.options and linker options, or --compileOnly , otherwise they get an error. They also have to use --passC:"-I/usr/lib/nim/lib" (for nimbase.h) .

Standard headers undefined at that time can still be used, if necessary (e. g. stdint.h), but should be enclosed in "" instead of <>, as they're "non-standard" and thus may not be provided by system.

The same support should be done for C99 (which allows inline, but not __inline), C11, C++11, C++14, and so on.

Code Examples

No response

Backwards Compatibility

No response

Araq commented 2 years ago

C89 is 23 years old, this is not a reasonable request. We support the C that all reasonably wide spread compilers support, including the extensions that they all agreed on.