Looking for memcpy() and memcmp() routines in C
Henry Spencer
henry at utzoo.uucp
Thu Feb 16 06:11:33 AEST 1989
In article <463 at sunset.MATH.UCLA.EDU> tony at MATH.UCLA.EDU () writes:
>Can somebody e-mail me C routines that copies (or compares) two
>structures of the same type?
Copying is fairly trivial; in fact, struct assignment is part of most
C compilers (although if he's got a real antique it may not be there).
Just "a = b;" where a and b are structs of the same type.
Nobody is going to be able to mail you C routines that reliably and
portably compare two structures of the same type, because it can't be
done without a member-by-member comparison. The compiler is entitled
to insert "holes" into a structure to meet alignment requirements for
following members, and there is no guarantee that those holes will
contain the same data in all structs, so a simple compare-N-bytes
function is not good enough.
--
The Earth is our mother; | Henry Spencer at U of Toronto Zoology
our nine months are up. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu
More information about the Comp.lang.c
mailing list