Skip to content

Commit a76be8f

Browse files
committed
Doc: Pacemaker Development: Prefer anonymous structs in typedefs
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 1c91f78 commit a76be8f

File tree

1 file changed

+32
-15
lines changed
  • doc/sphinx/Pacemaker_Development

1 file changed

+32
-15
lines changed

doc/sphinx/Pacemaker_Development/c.rst

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -608,21 +608,38 @@ Memory Management
608608
Structures
609609
##########
610610

611-
Changes to structures defined in public API headers (adding or removing
612-
members, or changing member types) are generally not possible without breaking
613-
API compatibility. However, there are exceptions:
614-
615-
* Public API structures can be designed such that they can be allocated only
616-
via API functions, not declared directly or allocated with standard memory
617-
functions using ``sizeof``.
618-
619-
* This can be enforced simply by documentating the limitation, in which case
620-
new ``struct`` members can be added to the end of the structure without
621-
breaking compatibility.
622-
623-
* Alternatively, the structure definition can be kept in an internal header,
624-
with only a pointer type definition kept in a public header, in which case
625-
the structure definition can be changed however needed.
611+
* Use an anonymous structure in a ``typedef`` unless the structure name is
612+
needed elsewhere. For example:
613+
614+
.. code-block:: c
615+
616+
// Do this
617+
typedef struct {
618+
char *name;
619+
char *value;
620+
} object_t;
621+
622+
// Not this
623+
typedef struct object_s {
624+
char *name;
625+
char *value;
626+
} object_t;
627+
628+
* Changes to structures defined in public API headers (adding or removing
629+
members, or changing member types) are generally not possible without
630+
breaking API compatibility. However, there are exceptions:
631+
632+
* Public API structures can be designed such that they can be allocated only
633+
via API functions, not declared directly or allocated with standard memory
634+
functions using ``sizeof``.
635+
636+
* This can be enforced simply by documentating the limitation, in which case
637+
new ``struct`` members can be added to the end of the structure without
638+
breaking compatibility.
639+
640+
* Alternatively, the structure definition can be kept in an internal header,
641+
with only a pointer type definition kept in a public header, in which case
642+
the structure definition can be changed however needed.
626643

627644

628645
.. index::

0 commit comments

Comments
 (0)