Jan Schmidt wrote:
<quote who="Benno">

On Sat Oct 16, 2004 at 16:21:04 +1000, Lucas King wrote:

how does one compare two structures of the same type?

You need to either compare each element, or use memcp; eg:

if (memcmp(&sin1, &sin2, sizeof sin1) == 0) {


}


and memcmp isn't usually a great idea, because most structures have padding
bytes that will be uninitialised (random) data.

J.

You can overcome this by memset(3)'ing the struc to zero's when it's allocated, or use calloc(3).


How usually do you compare structures? Member by member?

C++'s default comparison is at the bit level, how does it overcome
the "uninitialized padding" problem you pointed?

Cheers,

--Amos
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html

Reply via email to