apache / apache/nuttx

Reevaluate the C89 Requirement

Open
#6,896 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
C
Stars
4k
Forks
1.7k
Avg merge
1d 17h
Merged PRs (30d)
237

Description

The `C Coding Standard` states:
```
C Style Comments. C99/C11/C++ style comments (beginning with //) should not be used with NuttX. NuttX generally follows C89 and all code outside of architecture specific directories must be compatible with C89.
```

However, trying to compile NuttX with the gcc flag `-std=c89` results in many compiler errors.

For example, take this file: [include/nuttx/list.h
](https://github.com/apache/incubator-nuttx/blob/master/include/nuttx/list.h#L221-L409)
It uses the `inline` keyword, which is not a c89 feature: https://stackoverflow.com/questions/12151168/does-ansi-c-not-know-the-inline-keyword

Also see: https://gcc.gnu.org/onlinedocs/gcc/C-Dialect-Options.html
```
This turns off certain features of GCC that are incompatible with ISO C90 (when compiling C code), or of standard C++ (when compiling C++ code), such as the asm and typeof keywords, and predefined macros such as unix and vax that identify the type of system you are using. It also enables the undesirable and rarely used ISO trigraph feature. For the C compiler, it disables recognition of C++ style ‘//’ comments as well as the inline keyword.

The alternate keywords __asm__, __extension__, __inline__ and __typeof__ continue to work despite -ansi. You would not want to use them in an ISO C program, of course, but it is useful to put them in header files that might be included in compilations done with -ansi. Alternate predefined macros such as __unix__ and __vax__ are also available, with or without -ansi.
```

Since NuttX currently uses the `inline` keyword, it makes sense to reevaluate the C89 requirement.

Changing to C99/C11 gives access to many useful language features such as function pointers, _Bool (https://github.com/apache/incubator-nuttx/blob/master/include/stdbool.h#L64-L67), `__func__` macro, stdatomic, single line comments, and many other features. See https://cw.fel.cvut.cz/old/_media/courses/be5b99cpl/lectures/be5b99cpl-lec10-handout-3x3.pdf for a large list of other changes.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.