# Require C17 compiler to build CPython?

**URL:** <https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078>\
**Category:** Ideas\
**Created:** [August 6, 2024, 4:52am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078 "2024-08-06T04:52:48Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![skirpichev](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/skirpichev/32/10996_2.png) [@skirpichev](https://discuss.python.org/u/skirpichev)\
**Post date:** [August 6, 2024, 4:52am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/1 "2024-08-06T04:52:48Z")

</div>

That was [suggested before](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581), and since CPython 3.11 - c11 compiler is a [requirement](https://github.com/python/cpython/pull/100009), see also [discussion](https://discuss.python.org/t/requiring-compilers-c11-standard-mode-to-build-cpython/26481).

So why not c17? It’s essentially “c11 with bugfixes” and I believe all relevant compilers now support this standard.

---

<div class="post-metadata">

**Author:** ![ericvsmith](https://avatars.discourse-cdn.com/v4/letter/e/34f0e0/32.png) [@ericvsmith](https://discuss.python.org/u/ericvsmith)\
**Post date:** [August 6, 2024, 6:37am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/2 "2024-08-06T06:37:06Z")

</div>

What specific bug fixes are you interested in?

---

<div class="post-metadata">

**Author:** ![skirpichev](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/skirpichev/32/10996_2.png) [@skirpichev](https://discuss.python.org/u/skirpichev)\
**Post date:** [August 6, 2024, 8:07am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/3 "2024-08-06T08:07:58Z")

</div>

For me it’s, maybe, a very minor issue [DR#471](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2244.htm#dr_471). This now adopted by cmath.

---

<div class="post-metadata">

**Author:** ![gpshead](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/gpshead/32/54_2.png) [@gpshead](https://discuss.python.org/u/gpshead)\
**Post date:** [August 8, 2024, 12:43am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/4 "2024-08-08T00:43:09Z")

</div>

In the past whether we can do this or not is based on what the primary compiler on our Tier supported platforms require, and whether there are significant uses of other toolchains in non-tier platforms.

I don’t believe MSVC (Windows) supports more than C11 today based on [Microsoft C/C++ language conformance | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-170#c-standard-library-features-1).

We’d want a compelling widely applicable reason with no well contained targeted workarounds available to adopt a more recent standard. Our C11 requirement is very recent, only happening two years ago for Python 3.11+.

---

<div class="post-metadata">

**Author:** ![skirpichev](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/skirpichev/32/10996_2.png) [@skirpichev](https://discuss.python.org/u/skirpichev)\
**Post date:** [August 8, 2024, 1:54am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/5 "2024-08-08T01:54:15Z")

</div>

> [@gpshead](#):
>
> I don’t believe MSVC (Windows) supports more than C11 today

They claim support for C17 since [VS 2019](https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/).

> [@gpshead](#):
>
> to adopt a more recent standard

My point was, that it’s actually not a new standard, it’s same C11.

---

<div class="post-metadata">

**Author:** ![jrivers](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/jrivers/32/12134_2.png) [@jrivers](https://discuss.python.org/u/jrivers)\
**Post date:** [August 8, 2024, 5:58am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/6 "2024-08-08T05:58:36Z")

</div>

Are those functions (`cacosh` and `ctanh`) even used in CPython? The [`cmath` module](https://github.com/python/cpython/blob/main/Modules/cmathmodule.c) has its own implementation of all of its functions.

---

<div class="post-metadata">

**Author:** ![skirpichev](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/skirpichev/32/10996_2.png) [@skirpichev](https://discuss.python.org/u/skirpichev)\
**Post date:** [August 8, 2024, 6:19am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/7 "2024-08-08T06:19:53Z")

</div>

> [@jrivers](#):
>
> The [`cmath` module](https://github.com/python/cpython/blob/main/Modules/cmathmodule.c) has its own implementation of all of its functions.

That’s true, but they return C99 (now actually C17) Annex G recommended results.

---

<div class="post-metadata">

**Author:** ![ZeroIntensity](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/zerointensity/32/10639_2.png) [@ZeroIntensity](https://discuss.python.org/u/ZeroIntensity)\
**Post date:** [August 8, 2024, 8:59am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/8 "2024-08-08T08:59:02Z")

</div>

I was under the impression that specifying C17 over C11 did nothing on many compilers, as most of the fixes were backported.

---

<div class="post-metadata">

**Author:** ![storchaka](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/storchaka/32/217_2.png) [@storchaka](https://discuss.python.org/u/storchaka)\
**Post date:** [August 8, 2024, 9:53am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/9 "2024-08-08T09:53:08Z")

</div>

How does it work on practice? Do compilers link to different math libraries or map `cacosh` to different names depending on the C standard version? Or is there a global flag that affects its behavior? How is binary compatibility maintained between C11 and C17?

---

<div class="post-metadata">

**Author:** ![skirpichev](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/skirpichev/32/10996_2.png) [@skirpichev](https://discuss.python.org/u/skirpichev)\
**Post date:** [August 8, 2024, 10:15am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/10 "2024-08-08T10:15:31Z")

</div>

> [@storchaka](#):
>
> Do compilers link to different math libraries or map `cacosh` to different names depending on the C standard version?

Glibc maintainers just unconditionally turn on C17 behaviour. An example: [sourceware.org Git - glibc.git/commitdiff](https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=d15e83c5f5231d971472b5ffc9219d54056ca0f1)

I would expect same for others stdlib implementations. For example, referenced above MS blog post says: “Since C17 is essentially just a bug fix release of ISO C, with many defect reports being adopted, our support for C11 already includes all the relevant defect reports. At present, **there are no differences between the C11 and C17 versions except for the ` __STDC_VERSION__ ` macro, which expands to `201112L` (for C11) and `201710L` (for C17).**”

---

<div class="post-metadata">

**Author:** ![nmstoker](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/nmstoker/32/7444_2.png) [@nmstoker](https://discuss.python.org/u/nmstoker)\
**Post date:** [August 17, 2024, 5:05pm UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/11 "2024-08-17T17:05:22Z")

</div>

Out of interest, does Python 3.12 currently compile without errors if you switch it to use C17?

---

<div class="post-metadata">

**Author:** ![skirpichev](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/skirpichev/32/10996_2.png) [@skirpichev](https://discuss.python.org/u/skirpichev)\
**Post date:** [August 17, 2024, 5:47pm UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/12 "2024-08-17T17:47:15Z")

</div>

None (gcc-12) new warnings (only same as in the main, all for the decimal module).

> **patch**
>
> ```diff
> diff --git a/configure b/configure
> index c28c333550..5b1c71fa8a 100755
> --- a/configure
> +++ b/configure
> @@ -9834,7 +9834,7 @@ fi
>  
> case $GCC in
> yes)
> - CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
> + CFLAGS_NODIST="$CFLAGS_NODIST -std=c17"
>  
>  
>  
> diff --git a/configure.ac b/configure.ac
> index 9daace7179..d659a241a7 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -2525,7 +2525,7 @@ fi
>  
> case $GCC in
> yes)
> - CFLAGS_NODIST="$CFLAGS_NODIST -std=c11"
> + CFLAGS_NODIST="$CFLAGS_NODIST -std=c17"
>  
> PY_CHECK_CC_WARNING([enable], [extra], [if we can add -Wextra])
> AS_VAR_IF([ac_cv_enable_extra_warning], [yes],
> 
> ```

---

<div class="post-metadata">

**Author:** ![storchaka](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/storchaka/32/217_2.png) [@storchaka](https://discuss.python.org/u/storchaka)\
**Post date:** [August 17, 2024, 6:31pm UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/13 "2024-08-17T18:31:31Z")

</div>

Then what is the difference? If the math library contains the C17 changes, you get them in any case.

---

<div class="post-metadata">

**Author:** ![skirpichev](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/skirpichev/32/10996_2.png) [@skirpichev](https://discuss.python.org/u/skirpichev)\
**Post date:** [August 18, 2024, 2:48am UTC](https://discuss.python.org/t/require-c17-compiler-to-build-cpython/60078/14 "2024-08-18T02:48:59Z")

</div>

I think it’s only in documentation. We claim C11-compatibility, but in reality: when we require a C11 compiler and stdlib - we usually got C17-compatible compiler and stdlib.
