Frustrated trying to be portable

Doug Gwyn gwyn at smoke.brl.mil
Sun Mar 3 14:18:48 AEST 1991


In article <N4Q94O2 at xds13.ferranti.com> peter at ficc.ferranti.com (Peter da Silva) writes:
-In article <2960 at cirrusl.UUCP> dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:
-> [You can't implement it portably].  My portable solution, is to assume that
-> the caller of memmove() always knows the direction of the move.
-Are you sure? Either one of two situations exists:
-	The pointers are into the same object.
-	The pointers are into different objects.
-In the former case, overlap is a problem but you can compare them for
-magnitude. In the latter case, overlap is not a problem. The result of
-comparing two pointers into different objects is undefined but when you
-don't care about the result why worry?

Because any reliance on undefined behavior is obviously not portable,
as the man said.  In fact for a wide class of architectures, there is
no problem, but for some architectures the C run-time implementation
may trap on an attempt to compare two pointers to different objects.



More information about the Comp.std.c mailing list