Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: Re: [Ethereal-dev] Problems compiling ethereal 0.9.8 under MacOS X

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <guy@xxxxxxxxxx>
Date: Mon, 9 Dec 2002 12:11:56 -0800
On Mon, Dec 09, 2002 at 08:25:38AM -0600, Esh, Andrew wrote:
> The more correct initialization

Actually

	static const gchar hex_digits[16] = "0123456789abcdef";

is perfectly legitimate according to ANSI X3.159-1989, "American
National Standard for Information Systems -- Programming Language -- C"
(and presumably the ISO version thereof):

	3.5.7 Initialization

		...

	Semantics

		...

	   An array of character type may be initialized with a
	character string literal, optionally enclosed in braches. 
	Successive codes of the character string literal (including the
	terminating null character if there is room or if the array is
	of unknown size) initialize the elements of the array.

which does not require that the array be large enough to hold the entire
literal, including the terminating null character, whereas

	static const gchar hex_digits[16] = '0', '1', '2', '3', '4', '5',
		'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f';

is not, as far as I can tell, legitimate according to ANSI C - an
[init-declarator] is either a [declarator] or

	declarator = initializer

and an [initializer] is one of

	assignment-expression
	{ initializer-list }
	{ initializer-list , }

and an [assignment-expression] doesn't include comma operators.

Presumably you meant

	static const gchar hex_digits[16] = { '0', '1', '2', '3', '4', '5',
		'6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

which is certainly an acceptable *workaround* for the compiler/linker
*bug* in the MacOS X compiler/linker, and a cleaner workaround than
adding an extra 17th element to the array, but any C compiler/linker
that has problems with

	static const gchar hex_digits[16] = "0123456789abcdef";

in C code is *not* a valid implementation of ANSI C/ISO C.  ("3.5.7
Initialization" later says, in the "Examples" section:

	   Finally, the declaration

		char s[] = "abc", t[3] = "abc";

	declares ``plain'' char array objects s and t whose elements are
	initialized with string literals.  This declaration is identical
	to

		char s[] = { 'a', 'b', 'c', '\0' },
		     t[] = { 'a', 'b', 'c' };

.)