# when compiling Wireshark sources. (Selected from "level 4" warnings).
## 4295: array is too small to include a terminating null character
## 4189: local variable is initialized but not referenced
- set(WARNINGS_CFLAGS "/w34295 /w34189")
+ # Disable warnings about about use of flexible array members:
+ ## 4200: nonstandard extension used : zero-sized array in struct/union
+ set(WARNINGS_CFLAGS "/w34295 /w34189 /wd4200")
set(WIRESHARK_COMMON_FLAGS
${LOCAL_CFLAGS}
endif()
endif()
+ if(CMAKE_VERSION VERSION_LESS "3.1")
+ # Many modern compilers use c99 by default, but for older ones
+ # (like GCC 4.4.7), -std=gnu99 is required to avoid errors about
+ # use constructs like "for (int i = 0; i < n; i++) ;"
+ if(CMAKE_C_COMPILER_ID MATCHES "GNU")
+ set(CMAKE_C_FLAGS "-std=gnu99 ${CMAKE_C_FLAGS}")
+ endif()
+ else()
+ set(CMAKE_C_STANDARD 99)
+ endif()
+
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(WIRESHARK_COMMON_FLAGS ${WIRESHARK_COMMON_FLAGS}
# avoid "argument unused during compilation" warnings
# The Qt headers generate a ton of shortening errors on 64-bit systems
# so only enable this for C for now.
-Wshorten-64-to-32
- # Clang only
- -Wc99-extensions
)
set(CXX_WARN_FLAGS
different compilers; here are some rules for writing code that will work
on multiple platforms.
-Don't use C++-style comments (comments beginning with "//" and running
-to the end of the line) in C code. Wireshark's dissectors are written in
-C, and thus run through C rather than C++ compilers, and not all C
-compilers support C++-style comments (GCC does, but IBM's C compiler for
-AIX, for example, doesn't do so by default). C++-style comments can be
-used in C++ code, of course.
-
-In general, don't use C99 features since some C compilers used to compile
-Wireshark, such as Microsoft's C compiler, don't support all C99
+In general, not all C99 features can be used since some C compilers used to
+compile Wireshark, such as Microsoft's C compiler, don't support all C99
features. The C99 features that can be used are:
- variadic macros
+ - flexible array members
+ - compound literals
+ - designated initializers
+ - "//" comments
+ - mixed declarations and code
+ - new block scopes for selection and iteration statements (that is, declaring
+ the type in a for-loop like: for (int i = 0; i < n; i++) ;)
+ - macros with a variable number of arguments (variadic macros)
+ - trailing comma in enum declarations
+ - inline functions (guaranteed only by use of glib.h)
Don't initialize variables in their declaration with non-constant
values. Not all compilers support this. E.g. don't use
i = somearray[2];
instead.
-Don't use zero-length arrays; not all compilers support them. If an
-array would have no members, just leave it out.
-
-Don't declare variables in the middle of executable code; not all C
-compilers support that. Variables should be declared outside a
-function, or at the beginning of a function or compound statement.
+Don't use zero-length arrays as structure members, use flexible array members
+instead.
Don't use anonymous unions; not all compilers support them.
Example:
are little-endian, even though PCs are. Fetch those values using
"tvb_get_letohs()" and "tvb_get_letohl()".
-Don't put a comma after the last element of an enum - some compilers may
-either warn about it (producing extra noise) or refuse to accept it.
-
Do not use "open()", "rename()", "mkdir()", "stat()", "unlink()", "remove()",
"fopen()", "freopen()" directly. Instead use "ws_open()", "ws_rename()",
"ws_mkdir()", "ws_stat()", "ws_unlink()", "ws_remove()", "ws_fopen()",
initialize the array at the point at which it's first declared, so that
the size is known.
-Don't put a comma after the last tuple of an initializer of an array.
-
For #define names and enum member names, prefix the names with a tag so
as to avoid collisions with other names - this might be more of an issue
on Windows, as it appears to #define names such as DELETE and
my $fileContents = '';
my @foundAPIs = ();
my $line;
- my $prohibit_cpp_comments = 1;
if ($source_dir and ! -e $filename) {
$filename = $source_dir . '/' . $filename;
next;
}
- # Establish or remove local taboos
- if ($filename =~ m{ ui/qt/ }x) { $prohibit_cpp_comments = 0; }
- if ($filename =~ m{ image/*.rc }x) { $prohibit_cpp_comments = 0; }
-
# Read in the file (ouch, but it's easier that way)
open(FC, $filename) || die("Couldn't open $filename");
$line = 1;
#$errorCount += check_ett_registration(\$fileContents, $filename);
- if ($prohibit_cpp_comments && $fileContents =~ m{ \s// }xo)
- {
- print STDERR "Error: Found C++ style comments in " .$filename."\n";
- $errorCount++;
- }
-
# Remove all blank lines
$fileContents =~ s{ ^ \s* $ } []xog;