Skip to content

Commit 85e70f9

Browse files
encukouAA-Turnerhugovk
authored
PEP 7: Reword & split the "C dialect" section (GH-4557)
The motivation here is to avoid users reading PEP 7 as guarantees about what compilers/settings are required to build Python or extensions. I've also clarified a few things in line with current practice. --------- Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent 395f4db commit 85e70f9

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

peps/pep-0007.rst

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,24 @@ particular rule:
2626
clean up someone else's mess (in true XP style).
2727

2828

29-
C dialect
30-
=========
29+
.. _c_dialect:
30+
31+
C standards
32+
===========
33+
34+
Follow the following standards.
35+
For features that aren't in the relevant standard, use CPython-specific
36+
wrappers (for example: ``_Py_atomic_store_int32``, ``Py_ALWAYS_INLINE``,
37+
``Py_ARITHMETIC_RIGHT_SHIFT``; ``_Py_ALIGNED_DEF`` in public headers).
38+
When adding such wrappers, try to make them easy to adjust for unsupported
39+
compilers.
3140

3241
* Python 3.11 and newer versions use C11 without `optional features
33-
<https://en.wikipedia.org/wiki/C11_%28C_standard_revision%29#Optional_features>`_.
34-
The public C API should be compatible with C++.
42+
<https://en.wikipedia.org/wiki/C11_%28C_standard_revision%29#Optional_features>`__.
43+
The public C API should be compatible with C99 and C++.
44+
45+
(As a reminder to any users reading this: this PEP is a *style guide*; these
46+
rules are there to be broken.)
3547

3648
* Python 3.6 to 3.10 use C89 with several select C99 features:
3749

@@ -44,15 +56,19 @@ C dialect
4456
- C++-style line comments
4557

4658
* Python versions before 3.6 used ANSI/ISO standard C (the 1989 version
47-
of the standard). This meant (amongst many other things) that all
48-
declarations must be at the top of a block (not necessarily at the
49-
top of function).
59+
of the standard). This meant, amongst many other things, that all
60+
declarations were at the top of a block.
61+
62+
63+
Common C code conventions
64+
=========================
5065

51-
* Don't use compiler-specific extensions, such as those of GCC or MSVC
52-
(e.g. don't write multi-line strings without trailing backslashes).
66+
* Don't use compiler-specific extensions, such as those of GCC or MSVC.
67+
For example, don't write multi-line strings without trailing backslashes.
5368

54-
* All function declarations and definitions must use full prototypes
55-
(i.e. specify the types of all arguments).
69+
* All function declarations and definitions must use full prototypes.
70+
That is, specify the types of all arguments and use ``(void)`` to declare
71+
functions with no arguments.
5672

5773
* No compiler warnings with major compilers (gcc, VC++, a few others).
5874

0 commit comments

Comments
 (0)