Skip to content

Commit

Permalink
PEP 7: Add C pre-processor macro style recommendations
Browse files Browse the repository at this point in the history
  • Loading branch information
erlend-aasland committed Oct 30, 2023
1 parent f438266 commit 9ad0a65
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions peps/pep-0007.rst
Expand Up @@ -135,6 +135,20 @@ Code lay-out
return 0; /* "Forgive" adding a __dict__ only */
}

* Vertically align line continuation characters in multi-line macros.

* Macros intended to be used as a statement should use the
``do {... }while(0)``` macro idiom.
Example::

#define ADD_INT_MACRO(MOD, INT) do { \
if (PyModule_AddIntConstant((MOD), (#INT), (INT)) < 0) { \
goto error; \
} \
} while (0)

* ``#undef`` macros after use.

* Put blank lines around functions, structure definitions, and major
sections inside functions.

Expand Down Expand Up @@ -170,6 +184,9 @@ Naming conventions
* Macros should have a MixedCase prefix and then use upper case, for
example: ``PyString_AS_STRING``, ``Py_PRINT_RAW``.

* Macro parameters should use ``ALL_CAPS`` style,
so they are easily distinguishable from C variables and struct members.


Documentation Strings
=====================
Expand Down

0 comments on commit 9ad0a65

Please sign in to comment.