Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 7: Add C pre-processor macro style recommendations #3516

Merged
merged 9 commits into from
Nov 16, 2023
17 changes: 17 additions & 0 deletions peps/pep-0007.rst
Original file line number Diff line number Diff line change
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.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

* Macros intended to be used as a statement should use the
warsaw marked this conversation as resolved.
Show resolved Hide resolved
``do {... }while(0)``` macro idiom.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
Example::

#define ADD_INT_MACRO(MOD, INT) do { \
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
if (PyModule_AddIntConstant((MOD), (#INT), (INT)) < 0) { \
goto error; \
} \
} while (0)

* ``#undef`` macros after use.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved

* 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.
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved


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