summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-06-27 18:34:30 -0700
committerGuy Harris <guy@alum.mit.edu>2017-06-28 01:35:53 +0000
commitf975c1712ed36be1eca5d99130d82c0a65353b08 (patch)
treeb17fe3ade7f688a8cbdc3fd47993840b76408195
parent39b22b7411401275d07e101c441f9892cf384def (diff)
downloadwireshark-f975c1712ed36be1eca5d99130d82c0a65353b08.tar.gz
Don't worry about initializing auto aggregates with non-constant values.
On UN*X, you can get C99-or-later compilers, and we request that in the autoconf script, so it's really a requirement. At least as I read https://msdn.microsoft.com/en-us/library/34h23df8%28v=vs.100%29.aspx Visual Studio 2010 (and earlier, going back to VS .NET 2003) supports the "Use of block-scope variables initialized with nonconstant expressions", with an example of an aggregate (array) initialization involving function calls, so it sounds as if it's available on Windows with any version of VS that we support. (If I've missed something, it'll presumably show up when something is built with MSVC, and we can update this at that point.) So the only thing to avoid is initializing global or static variables with a value that has to be evaluated at run time (the ability to do that is probably present in most environments, as I think C++ constructors for variables with static storage duration might have to be evaluated before main() is called, but I guess few C compilers bother to use it). 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: I338eb0892e656c2ab59519e4bf76e1dfbec2fa7d Reviewed-on: https://code.wireshark.org/review/22434 Reviewed-by: Guy Harris <guy@alum.mit.edu> (cherry picked from commit e0a9192ebceba1e7d010a75592b101e4b80b952a) Reviewed-on: https://code.wireshark.org/review/22435
-rw-r--r--doc/README.developer25
1 files changed, 16 insertions, 9 deletions
diff --git a/doc/README.developer b/doc/README.developer
index 52df3a6fcc..aa375db636 100644
--- a/doc/README.developer
+++ b/doc/README.developer
@@ -82,25 +82,32 @@ features. The C99 features that can be used are:
- trailing comma in enum declarations
- inline functions (guaranteed only by use of glib.h)
-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 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];
-declare it as just
+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];
-instead. Initializations of non-aggregate variables with automatic
-storage duration - i.e., local variables - with non-constant values is
-permitted, so, within a function
+instead. Initializations of variables with automatic storage duration -
+i.e., local variables - with non-constant values is permitted, so,
+within a function
guint32 i = somearray[2];