structure and array and string comparisons

John Gilmore gnu at sun.uucp
Tue Mar 20 04:56:24 AEST 1984


If we do ANYTHING about this, we should do it right.  This means that
we can't embed "zero byte means end" into the language -- a character "string"
is simply an array of chars, and don't you forget it.  In any case,
we can't do array comparison, since an array is by definition converted
to a pointer to its first element every time it's used -- there's no way to
refer to the whole array except in sizeof.  When I want to pass an array
as an argument, I typically enclose it in a struct.  The flexibility of 
pointer==array==pointer is a big win but it has some minor losses like this.

Personally I think that avoiding structure comparison "because it's hard"
is a copout.  It's already "hard" for the C programmer who has to compare
each member of the structure individually.  For the compiler, 99% of the
cases are without holes and it's easy and efficient.

I don't propose comparing unions, or following pointers.  The comparison
s1 == s2 should be equivalent, except for storage reference pattern, to:

	( (s1.memb1 == s2.memb1) && (s1.memb2 == s2.memb2) && ...)



More information about the Comp.lang.c mailing list