]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141004: Document `Py_ARRAY_LENGTH` (GH-141601)
authorYashraj <yashrajpala8@gmail.com>
Mon, 24 Nov 2025 13:34:37 +0000 (19:04 +0530)
committerGitHub <noreply@github.com>
Mon, 24 Nov 2025 13:34:37 +0000 (13:34 +0000)
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Doc/c-api/intro.rst

index c39e006f059d309186a89abd9d0b9fceaae45114..bb94bcb86a7899e9427aa9c2b7d0e740c78c2305 100644 (file)
@@ -322,6 +322,19 @@ complete listing.
       PyDoc_VAR(python_doc) = PyDoc_STR("A genus of constricting snakes in the Pythonidae family native "
                                         "to the tropics and subtropics of the Eastern Hemisphere.");
 
+.. c:macro:: Py_ARRAY_LENGTH(array)
+
+   Compute the length of a statically allocated C array at compile time.
+
+   The *array* argument must be a C array with a size known at compile time.
+   Passing an array with an unknown size, such as a heap-allocated array,
+   will result in a compilation error on some compilers, or otherwise produce
+   incorrect results.
+
+   This is roughly equivalent to::
+
+      sizeof(array) / sizeof((array)[0])
+
 
 .. _api-objects: