Wireshark-dev: Re: [Wireshark-dev] Allowing use of more C99 features
From: Guy Harris <[email protected]>
Date: Thu, 1 Sep 2016 19:51:34 -0700
On Sep 1, 2016, at 1:14 PM, Peter Wu <[email protected]> wrote:

> Patch https://code.wireshark.org/review/17421 will allow use of some C99
> features in master (future 2.4):

For UN*X, with autotools:

	The AC_PROG_CC_C99 macro is used, and, if it fails to enable what it considers "C99 mode" for the compiler, the configure script will fail.  This means some older compilers may not be supported; it's probably time to drop those compilers.  The macro appears to try to enable it for:

		GCC (and Clang), using -std=gnu99
		IBM XL C, using -qlanglvl=extc99
		HP cc, using -AC99
		Intel ICC, using -std=c99
		SGI's C compiler for IRIX, using -c99
		Sun/Oracle's C compiler, using -xc99=all
		DEC/Compaq/HP's C compiler for Alpha on Tru64, using -c99

	so you're out of luck if you have a version of those compilers that doesn't support those flags and doesn't support all of:

		_Bool, // comments, flexible array members, inline, signed and unsigned long long int, mixed code and declarations, named initialization of structs, restrict, va_copy, varargs macros, variable declarations in for loops, and variable length arrays

For UN*X, with CMake:

	I'm not sure whether it'll properly enable C99 support for all of the compilers in question.

For Windows (CMake assumed), MSVC 2013 supports:

	// comments as long as you don't compile with /Za, but there might be a warning to suppress;

	flexible arrays, but there's a warning to suppress, which this change suppresses;

	inline functions - it might require __inline rather than inline, but GLib is #defining inline to be __inline with MSVC, so we can just use "inline";

	mixed code and declarations, but there's a bug that might or might not hit us:


	named initialization of structs, but there's a bug that might or might not hit us:


	varargs macros, which we're already using;

	variable declarations in for loops, apparently:


so, in addition to

> - flexible array members
> - trailing comma in enum declarations
> - inline function keyword

we also can use // comments and, apparently, variable declarations in for loops, assuming there's no bug that gets in the way.  *If* we avoid the bugs, we can also use mixed code and declarations and named initialization of structs.