From 81297fb91945beb65b75e16cfc91138b6cf3a310 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Thu, 2 Aug 2018 07:51:57 +0300 Subject: [PATCH] Update naming convention for structs The earlier guideline was just a "formalization" of existing conventions. --- Development/coding-style-and-guidelines.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Development/coding-style-and-guidelines.md b/Development/coding-style-and-guidelines.md index 99fef6368..9f1a6f886 100644 --- a/Development/coding-style-and-guidelines.md +++ b/Development/coding-style-and-guidelines.md @@ -107,10 +107,20 @@ typedef enum { ... } gwbuf_type_t; typedef enum gwbuf_type { ... } gwbuf_type_t; ``` ### structs +A `struct` must be a POD type. It must have no non-POD members and it must +not have any member functions. Whether a `struct` has been declared in a C +or C++ header file, it must be declared as if it would be used from C. + +In a C header, a `struct` is declared as: ``` -struct gw_protocol { ... }; -typedef struct { ... } GW_PROTOCOL; -typedef struct gw_protocol { ... } GW_PROTOCOL; +typedef struct SOME_TYPE { ... } SOME_TYPE; +``` +With this arrangement it is possible to refer to the type using `SOME_TYPE` +or `struct SOME_TYPE` from both C and C++ code. + +In a C++ header, a `struct` is declared without the typedef. +``` +struct SOME_TYPE; ``` ### functions