# Why Python is not compiled against C18?

**URL:** <https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581>\
**Category:** Ideas\
**Created:** [November 4, 2019, 9:45am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581 "2019-11-04T09:45:17Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 4, 2019, 9:45am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/1 "2019-11-04T09:45:17Z")

</div>

I noticed that Python is compiled against the C99 version. Why not allowing C18 (aka C17 aka C11 with clarifications for compilers)? It has a better unicode and threading support.

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [November 4, 2019, 2:01pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/2 "2019-11-04T14:01:32Z")

</div>

AFAIK, not all compilers support C18.  
Python actually uses _C89 with several select C99 features_, see [PEP 7](https://www.python.org/dev/peps/pep-0007/#c-dialect).

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 4, 2019, 2:12pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/3 "2019-11-04T14:12:31Z")

</div>

Yes, you’re right, it’s only supported by `gcc` and `llvm`. But I think `c11` is supported by a vast number of compilers.

I think PEP 7 could add to the selected features also unicode  
and threading from `c11` (or `c18` if the compiler supports it).

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 4, 2019, 3:07pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/5 "2019-11-04T15:07:47Z")

</div>

Mh, I’ve done a little search, and it seems MSVC does not support `thread.h` and sometimes acts strangely with variadic macros…

I think anyway unicode and restrict could be a good addition.

---

<div class="post-metadata">

**Author:** ![vstinner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/vstinner/32/15130_2.png) [@vstinner](https://discuss.python.org/u/vstinner)\
**Post date:** [November 5, 2019, 2:06am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/6 "2019-11-05T02:06:23Z")

</div>

> [@Marco\_Sulla](#):
>
> PS: I think also exclusive create for `fopen` is good

You can build this function using:

`fd=open(filename, O_EXCL | ...); f = fdopen(fd, "...");`

---

<div class="post-metadata">

**Author:** ![vstinner](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/vstinner/32/15130_2.png) [@vstinner](https://discuss.python.org/u/vstinner)\
**Post date:** [November 5, 2019, 2:08am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/7 "2019-11-05T02:08:00Z")

</div>

> [@Marco\_Sulla](#):
>
> I think anyway unicode and restrict could be a good addition.

I’m not sure which kind of problem you are trying to solve. Python already supports Unicode. We use the wchar\_t type and L"…" wide character string literals.

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 5, 2019, 10:57am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/8 "2019-11-05T10:57:45Z")

</div>

Well, for what I know, `u` literals can be optimized by the compiler, and `wchar_t` is platform-dependent. And what about `restrict`?

---

<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:** [November 5, 2019, 11:23am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/9 "2019-11-05T11:23:29Z")

</div>

`u"..."` is a 16-bit wide string literal. For what do you need it in the CPython core?

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [November 5, 2019, 11:43am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/10 "2019-11-05T11:43:34Z")

</div>

> [@Marco\_Sulla](#):
>
> Well, for what I know, `u` literals can be optimized by the compiler, and `wchar_t` is platform-dependent.

Write the patch, measure the impact, and if it’s an improvement, let’s get it in with `#ifdef` for compilers that don’t support it.

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 5, 2019, 12:26pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/11 "2019-11-05T12:26:57Z")

</div>

_sigh_ which compilers CPython officially supports?

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 5, 2019, 12:46pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/12 "2019-11-05T12:46:34Z")

</div>

For what I know, Chromium builds against `C11`, depending on the platform, even if the target can be `C99` without problems. Maybe this activates some optimizations?

I think it’s not a bad idea to compile against `C11`, or better `C18`, if the compiler supports it, even if `C11` unicode will be not used in CPython.

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [November 5, 2019, 1:14pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/13 "2019-11-05T13:14:47Z")

</div>

> [@Marco\_Sulla](#):
>
> _sigh_ which compilers CPython officially supports?

Ones that support C89 with the C99 features listed in [PEP 7](https://www.python.org/dev/peps/pep-0007/#c-dialect).

> [@Marco\_Sulla](#):
>
> For what I know, Chromium builds against `C11` , depending on the platform.

Chromium is not relevant.  
You are making suggestions without mentioning _what actual problems_ they will solve. That is not very useful.

> [@Marco\_Sulla](#):
>
> I think it’s not a bad idea to compile against `C11` , or better `C18` , if the compiler supports it, even if `C11` unicode will be not used in CPython.

Please do that! If you find that it results in an improvement, _then_ let’s figure out how to best move there.

---

<div class="post-metadata">

**Author:** ![benjamin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/benjamin/32/431_2.png) [@benjamin](https://discuss.python.org/u/benjamin)\
**Post date:** [November 5, 2019, 3:03pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/14 "2019-11-05T15:03:28Z")

</div>

Python is conservative about C language features because

1. Python tries to support a lowest common denominator of systems. Traditionally, this has meant supporting many proprietary Unixes each with their own proprietary C compiler. These days, there are a lot less weird compilers around than the 90s, but there are still people compiling Python themselves on very old systems with old versions of GCC or Clang. MSVC has also historically been slow to implement pure C features. That’s why we only started requiring C99 a few years ago.
2. New C features aren’t that interesting. The evolution of the C language itself has been conservative for decades.

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 5, 2019, 7:15pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/15 "2019-11-05T19:15:10Z")

</div>

> Write the patch, measure the impact

Ok, do you know if there’s a place in particular where can I can do the patch and test it? Maybe `unicodeobject.c`, `bytesobject.c` or both? Should I test `str`, `bytes`, `bytearray` or all of them? Is it `timeit` good enough? I see do you have a test suite, do you have also a benchmark suite?

> and if it’s an improvement, let’s get it in with `#ifdef` for compilers that don’t support it.

Sure. Do you want also a coffee?

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 5, 2019, 7:41pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/16 "2019-11-05T19:41:07Z")

</div>

> New C features aren’t that interesting

Well, I agree, indeed I was interested in threading and unicode only. But C11 threading system is not supported by MSVC…

Compiling Python on Windows with GCC produces a slower build?

---

<div class="post-metadata">

**Author:** ![encukou](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/encukou/32/2461_2.png) [@encukou](https://discuss.python.org/u/encukou)\
**Post date:** [November 5, 2019, 8:38pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/17 "2019-11-05T20:38:28Z")

</div>

> [@Marco\_Sulla](#):
>
> Ok, do you know if there’s a place in particular where can I can do the patch and test it? Maybe `unicodeobject.c` , `bytesobject.c` or both? Should I test `str` , `bytes` , `bytearray` or all of them? Is it `timeit` good enough? I see do you have a test suite, do you have also a benchmark suite?

No, I don’t know. I don’t know what you are trying to accomplish.  
I assumed you want to switch to C18 because something would be faster. But I still don’t know what you think would be faster. Or maybe my assumption was not correct.

---

<div class="post-metadata">

**Author:** ![benjamin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/benjamin/32/431_2.png) [@benjamin](https://discuss.python.org/u/benjamin)\
**Post date:** [November 6, 2019, 3:02am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/18 "2019-11-06T03:02:09Z")

</div>

> [@Marco\_Sulla](#):
>
> Compiling Python on Windows with GCC produces a slower build?

It doesn’t matter which is faster; we aren’t going to drop MSVC support.

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 6, 2019, 12:01pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/19 "2019-11-06T12:01:48Z")

</div>

Well, I respect your decision, even if I must say that if every important project continues to support `MSVC`, Microsoft will be never convinced to improve it. Edge was developed because people started to drop IE in favor of Firefox and Chromium/Chrome later. And now we have a lot of programmers that dropped the IE support, for Goddess’ sake.

---

<div class="post-metadata">

**Author:** ![Marco\_Sulla](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/marco_sulla/32/1451_2.png) [@Marco\_Sulla](https://discuss.python.org/u/Marco_Sulla)\
**Post date:** [November 6, 2019, 12:10pm UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/20 "2019-11-06T12:10:10Z")

</div>

@encukou: well, in theory unicode literals would be faster. Is there a bench suite in CPython code? I searched in Tools but I have not found one.

---

<div class="post-metadata">

**Author:** ![benjamin](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/benjamin/32/431_2.png) [@benjamin](https://discuss.python.org/u/benjamin)\
**Post date:** [November 7, 2019, 2:53am UTC](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581/21 "2019-11-07T02:53:03Z")

</div>

Again if there was an extremely compelling reason to use C18, we could consider tightening our compiler requirements, but there isn’t.

[Next page](https://discuss.python.org/t/why-python-is-not-compiled-against-c18/2581.md?page=2)
