Skip to content

Commit c9ad3d4

Browse files
committed
c standard: Enforce C17 as the minimum required C standard
C99 has been the minimum required C standard version for Zephyr since its inception. After multiple attempts and discussions, a decision has been made to upgrade to C17 going forward. This commits replaces the default C standard from C99 to C17 in the configuration and build system. Signed-off-by: Carles Cufi <[email protected]>
1 parent 8f60b74 commit c9ad3d4

File tree

8 files changed

+16
-100
lines changed

8 files changed

+16
-100
lines changed

CMakeLists.txt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,12 +319,6 @@ if(CONFIG_STD_C23)
319319
set(CSTD c2x)
320320
elseif(CONFIG_STD_C17)
321321
set(CSTD c17)
322-
elseif(CONFIG_STD_C11)
323-
set(CSTD c11)
324-
elseif(CONFIG_STD_C99)
325-
set(CSTD c99)
326-
elseif(CONFIG_STD_C90)
327-
set(CSTD c90)
328322
else()
329323
message(FATAL_ERROR "Unreachable code. Expected C standard to have been chosen.")
330324
endif()
@@ -409,7 +403,7 @@ if(CONFIG_COMPILER_FREESTANDING)
409403
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:compiler,freestanding>>)
410404
endif()
411405

412-
if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT)
406+
if(CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT)
413407
# @Intent: Set compiler specific flag to disable printf-related optimizations
414408
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_printf_return_value>>)
415409
endif()
@@ -1157,7 +1151,7 @@ endif()
11571151

11581152
get_property(OUTPUT_FORMAT GLOBAL PROPERTY PROPERTY_OUTPUT_FORMAT)
11591153

1160-
if (CONFIG_CODE_DATA_RELOCATION)
1154+
if(CONFIG_CODE_DATA_RELOCATION)
11611155
set(CODE_RELOCATION_DEP code_relocation_source_lib)
11621156
endif() # CONFIG_CODE_DATA_RELOCATION
11631157

@@ -2134,7 +2128,7 @@ if(CONFIG_BUILD_OUTPUT_INFO_HEADER)
21342128
)
21352129
endif()
21362130

2137-
if (CONFIG_LLEXT AND CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID)
2131+
if(CONFIG_LLEXT AND CONFIG_LLEXT_EXPORT_BUILTINS_BY_SLID)
21382132
#slidgen must be the first post-build command to be executed
21392133
#on the Zephyr ELF to ensure that all other commands, such as
21402134
#binary file generation, are operating on a preparated ELF.
@@ -2200,7 +2194,7 @@ if(signing_script)
22002194
endif()
22012195

22022196
# Generate USB-C VIF policies in XML format
2203-
if (CONFIG_BUILD_OUTPUT_VIF)
2197+
if(CONFIG_BUILD_OUTPUT_VIF)
22042198
include(${CMAKE_CURRENT_LIST_DIR}/cmake/vif.cmake)
22052199
endif()
22062200

@@ -2251,7 +2245,7 @@ if(LOG_DICT_DB_NAME_ARG)
22512245
--build-header ${PROJECT_BINARY_DIR}/include/generated/zephyr/version.h
22522246
)
22532247

2254-
if (NOT CONFIG_LOG_DICTIONARY_DB_TARGET)
2248+
if(NOT CONFIG_LOG_DICTIONARY_DB_TARGET)
22552249
# If not using a separate target for generating logging dictionary
22562250
# database, add the generation to post build command to make sure
22572251
# the database is actually being generated.

Kconfig.zephyr

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -355,20 +355,8 @@ endmenu
355355

356356
menu "Compiler Options"
357357

358-
config REQUIRES_STD_C99
359-
bool
360-
help
361-
Hidden option to select compiler support C99 standard or higher.
362-
363-
config REQUIRES_STD_C11
364-
bool
365-
select REQUIRES_STD_C99
366-
help
367-
Hidden option to select compiler support C11 standard or higher.
368-
369358
config REQUIRES_STD_C17
370359
bool
371-
select REQUIRES_STD_C11
372360
help
373361
Hidden option to select compiler support C17 standard or higher.
374362

@@ -381,31 +369,10 @@ config REQUIRES_STD_C23
381369
choice STD_C
382370
prompt "C Standard"
383371
default STD_C23 if REQUIRES_STD_C23
384-
default STD_C17 if REQUIRES_STD_C17
385-
default STD_C11 if REQUIRES_STD_C11
386-
default STD_C99
372+
default STD_C17
387373
help
388374
C Standards.
389375

390-
config STD_C90
391-
bool "C90"
392-
depends on !REQUIRES_STD_C99
393-
help
394-
1989 C standard as completed in 1989 and ratified by ISO/IEC
395-
as ISO/IEC 9899:1990. This version is known as "ANSI C".
396-
397-
config STD_C99
398-
bool "C99"
399-
depends on !REQUIRES_STD_C11
400-
help
401-
1999 C standard.
402-
403-
config STD_C11
404-
bool "C11"
405-
depends on !REQUIRES_STD_C17
406-
help
407-
2011 C standard.
408-
409376
config STD_C17
410377
bool "C17"
411378
depends on !REQUIRES_STD_C23

arch/Kconfig

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ config ARCH_POSIX
152152
select BARRIER_OPERATIONS_BUILTIN
153153
# POSIX arch based targets get their memory cleared on entry by the host OS
154154
select SKIP_BSS_CLEAR
155-
# Override the C standard used for compilation to C 2011
156-
# This is due to some tests using _Static_assert which is a 2011 feature, but
157-
# otherwise relying on compilers supporting it also when set to C99.
158-
# This was in general ok, but with some host compilers and C library versions
159-
# it led to problems. So we override it to 2011 for the native targets.
160-
select REQUIRES_STD_C11
161155
help
162156
POSIX (native) architecture
163157

cmake/compiler/compiler_features.cmake

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
set(c23id c2x gnu2x)
1+
set(c23id c2x gnu2x "iso9899:2023" "iso9899:2024")
22
set(c17id c17 c18 gnu17 gnu18 "iso9899:2017" "iso9899:2018")
3-
set(c11id c11 gnu11 "iso9899:2011")
4-
set(c99id c99 gnu99 "iso9899:1999")
5-
set(c90id c89 c90 gnu89 gnu90 "iso9899:1990" "iso9899:199409")
63

74
set(compile_features_list)
85

96
# For each id value above a compile_features_${idval} with a list of supported
107
# `c_std_XX` values are created for easy lookup.
118
# For example, the settings
12-
# - `compile_feature_c99` will contain `c_std_90;c_std_99`
13-
# - `compile_feature_iso9899:2011` will contain `c_std_90;c_std_99;c_std_11`
9+
# - `compile_feature_c23` will contain `c_std_17;c_std_23`
10+
# - `compile_feature_iso9899:2023` will contain `c_std_17;c_std_23`
1411
# that can then be used to set CMAKE_C_COMPILE_FEATURES accordingly.
15-
foreach(standard 90 99 11 17 23)
12+
foreach(standard 17 23)
1613
list(APPEND compile_features_list c_std_${standard})
1714
foreach(id ${c${standard}id})
1815
set(compile_features_${id} ${compile_features_list})

doc/develop/languages/c/index.rst

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,21 @@ Language Standards
2424

2525
Zephyr does not target a specific version of the C standards; however, the
2626
Zephyr codebase makes extensive use of the features newly introduced in the
27-
1999 release of the ISO C standard (ISO/IEC 9899:1999, hereinafter referred to
28-
as C99) such as those listed below, effectively requiring the use of a compiler
29-
toolchain that supports the C99 standard and above:
27+
2017 release of the ISO C standard (ISO/IEC 9899:2017, hereinafter referred to
28+
as C17) such as those listed below, effectively requiring the use of a compiler
29+
toolchain that supports the C17 standard and above:
3030

3131
* inline functions
3232
* standard boolean types (``bool`` in ``<stdbool.h>``)
3333
* fixed-width integer types (``[u]intN_t`` in ``<stdint.h>``)
3434
* designated initializers
3535
* variadic macros
3636
* ``restrict`` qualification
37-
38-
Some Zephyr components make use of the features newly introduced in the 2011
39-
release of the ISO C standard (ISO/IEC 9899:2011, hereinafter referred to as
40-
C11) such as the type-generic expressions using the ``_Generic`` keyword. For
41-
example, the :c:func:`cbprintf` component, used as the default formatted output
42-
processor for Zephyr, makes use of the C11 type-generic expressions, and this
43-
effectively requires most Zephyr applications to be compiled using a compiler
44-
toolchain that supports the C11 standard and above.
37+
* _Generic keyword
38+
* _Static_assert keyword
4539

4640
In summary, it is recommended to use a compiler toolchain that supports at
47-
least the C11 standard for developing with Zephyr. It is, however, important to
41+
least the C17 standard for developing with Zephyr. It is, however, important to
4842
note that some optional Zephyr components and external modules may make use of
4943
the C language features that have been introduced in more recent versions of
5044
the standards, in which case it will be necessary to use a more up-to-date

modules/nanopb/Kconfig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ config ZEPHYR_NANOPB_MODULE
66

77
menuconfig NANOPB
88
bool "Nanopb Support"
9-
# Nanopb requires c_std_11 compiler features like _Static_assert
10-
select REQUIRES_STD_C11
119
help
1210
This option enables the Nanopb library and generator.
1311

tests/subsys/bindesc/definition/testcase.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,9 @@ tests:
1919
- qemu_riscv32
2020
- qemu_riscv32e
2121
- qemu_riscv64
22-
bindesc.define.c99:
23-
extra_configs:
24-
- CONFIG_STD_C99=y
25-
bindesc.define.c11:
26-
extra_configs:
27-
- CONFIG_STD_C11=y
2822
bindesc.define.c17:
2923
extra_configs:
3024
- CONFIG_STD_C17=y
31-
bindesc.define.gnu99:
32-
extra_configs:
33-
- CONFIG_STD_C99=y
34-
- CONFIG_GNU_C_EXTENSIONS=y
35-
bindesc.define.gnu11:
36-
extra_configs:
37-
- CONFIG_STD_C11=y
38-
- CONFIG_GNU_C_EXTENSIONS=y
3925
bindesc.define.gnu17:
4026
extra_configs:
4127
- CONFIG_STD_C17=y

tests/subsys/bindesc/reading/testcase.yaml

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,9 @@ tests:
88
bindesc.read:
99
platform_allow:
1010
- native_sim
11-
bindesc.read.c99:
12-
extra_configs:
13-
- CONFIG_STD_C99=y
14-
bindesc.read.c11:
15-
extra_configs:
16-
- CONFIG_STD_C11=y
1711
bindesc.read.c17:
1812
extra_configs:
1913
- CONFIG_STD_C17=y
20-
bindesc.read.gnu99:
21-
extra_configs:
22-
- CONFIG_STD_C99=y
23-
- CONFIG_GNU_C_EXTENSIONS=y
24-
bindesc.read.gnu11:
25-
extra_configs:
26-
- CONFIG_STD_C11=y
27-
- CONFIG_GNU_C_EXTENSIONS=y
2814
bindesc.read.gnu17:
2915
extra_configs:
3016
- CONFIG_STD_C17=y

0 commit comments

Comments
 (0)