Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Looking for memcpy() and memcmp() routines in C Message-ID: <9725@smoke.BRL.MIL> Date: 26 Feb 89 05:40:32 GMT References: <463@sunset.MATH.UCLA.EDU> <20598@tiger.oxy.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 32 In article <20598@tiger.oxy.edu> bagpiper@oxy.edu (Michael Paul Hunter) writes: >In article <463@sunset.MATH.UCLA.EDU> tony@joshua.math.ucla.edu writes: >>Can somebody e-mail me C routines that copies (or compares) two >>structures of the same type? >If your compiler will pass structures you can create a routine like the >one which follows to copy structures. The easiest way to copy a struct is to use assignment (=). >I think there might be a probablem in comparing byte by byte in that >their could be unused space (well it is used for alignment) which might >contain different values even though two different structure are the same >member for member. Not only that, but if you're testing for anything but exact equality you'd probably get the wrong results by comparing bytes instead of the actual object members. Also note that string members should be compared via strcmp() and not just for pointer equality or as arrays. >What does the proposed ANSI spec say (BTW, when well it not be proposed >anymore?) and what do older compilers do? The pANS requires support for struct assignment, struct function parameters, and struct function return values. These have actually been implemented in most C compilers since around 1978. Struct comparison is not supported, because there is no unambiguously correct way to do it, as noted above. The application itself must implement whatever is appropriate for this. The proposed ANSI C standard is being reviewed by X3, with balloting to end early in March. If X3 approves it, the proposed standard will then be sent to ANSI and it is unlikely in the extreme that it would not be accepted as the official ANS for C at that point.