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: Michael Tuexen <Michael.Tuexen@xxxxxxxxxxxxxxxxx>
Date: Mon, 9 Dec 2002 22:08:02 +0100
Guy,

I understand that it is a problem of the MacOS X compiler/linker.

Is it acceptable to check in the following patch

Index: epan/to_str.c
===================================================================
RCS file: /usr/local/cvsroot/ethereal/epan/to_str.c,v
retrieving revision 1.20
diff -r1.20 to_str.c
88c88,89
<   static const gchar hex_digits[16] = "0123456789abcdef";
---
> static const gchar hex_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', > '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
217c218,219
<   static const gchar hex_digits[16] = "0123456789ABCDEF";
---
> static const gchar hex_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', > '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
574c576,577
<   static const gchar hex_digits[16] = "0123456789abcdef";
---
> static const gchar hex_digits[16] = {'0', '1', '2', '3', '4', '5', '6', '7', > '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

or should I #ifdef the code for MacOS X?

Best regards
Michael

On Monday, Dec 9, 2002, at 21:11 Europe/Berlin, Guy Harris wrote:

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' };

.)