At 11:44 AM +1000 7/10/02, George Bassili wrote:
>I have 2 TimeType structures as follows:
>
>TimeType start = {12,30);
>TimeType end = {13,30);
>
>and i find if i try to compare them to check if they're the same i
>get an illegal operand error.
>
>If (start == end) {.....}
>
>So i Guess i need to compare each element one by one as follows:
>
>if (start.hours = end.hours and start.minutes = end.minutes) {......}
>
>This works but why wouldn't the compiler just compare the 2 chunks
>of mempoy in the first case. In other words would this work??? :
>
>if (MemCmp ((void *)&start, (void *)&end, sizeof(TimeType)) == 0) {....}
>
>Is this a c thing that maybe c only supports comparisons of its
>primitive types? I'm just not sure why my first piece of code won't
>work.
Yes, this is a C thing. One good reason for not doing a MemCmp
approach is that you don't necessarily know if there are any unused
bytes or "holes" in your structure. If there are, they will be
filled with uninitialized values that will cause your comparison to
fail even when all legitimate members are equal.
I don't know why C doesn't have a memberwise compare operation for
structs. Perhaps the original language architects didn't want to
over-burden the language with operations that contained hidden costs.
-- Keith
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/