structure and array and string comparisons

Donald Wallace Rouse II dwr at ccieng6.UUCP
Thu Mar 29 15:23:23 AEST 1984


The version of C that I use allows compile-time initialization of the
non-union elements of non-automatic structures, as:

	static struct s
		{
		int	e1;
		char	e2;
		union
			{
			int	e31;
			double	e32;
			} e3;
		} x = { 1, 'c' };

If C special-cases initialization in this way, there is no reason it
can't special-case comparisons of structures containing unions.  I
agree that comparisons other than == != are probably not too useful.
Don't worry about holes; let the compiler do it.  If the compiler can
keep track of holes during initialization, there is no reason that it
can't keep track of them during comparison and generate appropriate
code to skip them.

On a slightly related topic, my favorite extension to C would be
structure and array constants on the right-hand side of assignment
expressions, as:

	int x ()
		{
		struct s	x;
		int		i [5];

		if (expr)
			x = { 4, 'x' };
		else
			i = { 1, 2, 3, 4, 5 };
		}
									D2



More information about the Comp.lang.c mailing list