What Can't C Do?

Guy Harris guy at rlgvax.UUCP
Wed Mar 21 03:43:37 AEST 1984


>> <>
>>  > While you're on the subject, what about == to compare two structures?
>>  > This is even more reasonable, in that structure assignment is supported...
>> Yet another bad idea.  This is much harder than it looks, for at least the
>> following reasons: ....

> However -- comparing two structure of identical names is useful. Tells the
> compiler to do byte-for-byte compare inline. Equality and inequality are
> obvious, but I wouldn't want to count on  < or >.

You missed his point; to correctly compare two structures a byte-for-byte
comparsion should *not* be done.  The bytes which are not part of structure
members, but which are just padding to put structure members on the right
boundary, *must* not be compared or two structures which "should" be equal
won't compare equal.

Yes, the comparison would be nice, but it's not trivial to implement and
won't compile into a simple comparison.  Also, < and > are flatly impossible;
what about

	struct complex {
		double	realpart;
		double	imagpart;
	};

Any result of < and > would be misleading as the complex numbers aren't an
ordered field.

	Guy Harris
	{seismo,ihnp4,allegra}!rlgvax!guy



More information about the Comp.lang.c mailing list