diff options
author | Guy Harris <guy@alum.mit.edu> | 2017-06-27 18:44:39 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-06-28 01:45:23 +0000 |
commit | 0930fe4cffc3f9b4a8ef9168a72fdb05c8f1bcb8 (patch) | |
tree | 15a08bca21ea3bbf21e1a1c9a24d0507ecb0b71b | |
parent | b8273a1497ce7743fb5a818b70aa88d69a9f2b96 (diff) | |
download | wireshark-0930fe4cffc3f9b4a8ef9168a72fdb05c8f1bcb8.tar.gz |
Clean up the "non-constant initalizers" stuff.
We aren't, in this branch, insisting on C99 on UN*X, so we still warn
against initializing aggregates, even if they have automatic storage
duration, with non-constant values. Put that into its own section, with
some details, and take that out of the section on initializing global
and static variables with non-constant values.
(In practice, it'll probably Just Work, but we haven't pulled any of the
*other* C99isms into this branch, and this branch is soon going to be
less active once 2.4 is out, so we'll just leave the restrictions in.)
For the latter section, expand the example in the hopes of avoiding
confusion between "static storage duration" (which something declared
"static" has, but which anything declared with file scope, whether
declared "static" or not, also has) and "static storage duration and
internal linkage", which is what the "static" keyword specifies.
Change-Id: I5a7d307f0cb3be84e355b92231fb115359d0cd41
Reviewed-on: https://code.wireshark.org/review/22436
Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r-- | doc/README.developer | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/doc/README.developer b/doc/README.developer index 621393eac3..2ad38095f9 100644 --- a/doc/README.developer +++ b/doc/README.developer @@ -80,18 +80,43 @@ features. The C99 features that can be used are: variadic macros -Don't initialize variables with static storage duration - i.e., global -or static variables - or objects with aggregate type (arrays and -structures) in their declaration with non-constant values. Not all -compilers support this. E.g., if "i" is a static or global variable, -don't declare i as +Don't initialize array, structure, or union variables (variables with +aggregate type) in their declaration with non-constant values. Not all +compilers support this. E.g., if "foo" is a structure with two guint32 +members "a" and "b", don't declare it as - guint32 i = somearray[2]; + struct xxx foo = { somearray[2], somearray[1] }; declare it as just + struct xxx foo; + +and later, in code, initialize it with + + foo.a = somearray[2]; + foo.b = somearray[1]; + +instead. + +Don't initialize global or static variables (variables with static +storage duration) in their declaration with non-constant values. Not +all compilers support this. E.g., if "i" is a static or global +variable, don't declare "i" as + + guint32 i = somearray[2]; + +outside a function, or as + + static guint32 i = somearray[2]; + +inside or outside a function, declare it as just + guint32 i; +or + + static guint32 i; + and later, in code, initialize it with i = somearray[2]; |