The branch, master has been updated
       via  f824e985167 doc: Update codeing guidelines for struct initialisation
      from  ac7a16f9cc4 smbd: Fix crossing automounter mount points

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f824e985167f08df80a5cf635809eed6573b2e13
Author: Noel Power <noel.po...@suse.com>
Date:   Thu Jun 27 09:02:04 2024 +0100

    doc: Update codeing guidelines for struct initialisation
    
    Signed-off-by: Noel Power <noel.po...@suse.com>
    Reviewed-by: Ralph Boehme <s...@samba.org>
    Reviewed-by: Douglas Bagnall <douglas.bagn...@catalyst.net.nz>
    Reviewed-by: Andreas Schneider <a...@samba.org>
    
    Autobuild-User(master): Noel Power <npo...@samba.org>
    Autobuild-Date(master): Fri Jun 28 10:17:14 UTC 2024 on atb-devel-224

-----------------------------------------------------------------------

Summary of changes:
 README.Coding.md | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)


Changeset truncated at 500 lines:

diff --git a/README.Coding.md b/README.Coding.md
index 76f2c70e95a..53a829cb4f2 100644
--- a/README.Coding.md
+++ b/README.Coding.md
@@ -390,6 +390,48 @@ Bad Example:
 
        pointer1 = some_func1();
 ```
+### Initialize structs
+
+All structures MUST be at least initialised to 0/NULL.
+
+Current recommended initialization:
+
+```c
+        struct somestruct {
+                int ival;
+                bool bval;
+                double dval;
+                char *sval;
+        };
+
+        struct somestruct var1 = {};
+```
+
+avoid:
+
+```c
+        struct somestruct var1 = {0};
+```
+
+as it can be less portable, in particular if the first element of the struct 
in question is a nested struct.
+
+Of course if specific members need non-zero initialization then use something 
like:
+
+```c
+        struct bar {
+            int inner;
+        };
+        struct foo {
+                int outer;
+                struct bar nested;
+        };
+        struct foo var2 = {
+                .outer = 5,
+                .nested = {
+                        .inner = 3,
+                },
+        };
+```
 
 ### Make use of helper variables
 


-- 
Samba Shared Repository

Reply via email to