Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!peregrine!sceard!ncr-sd!iss-rb!tortuga!rns From: rns@tortuga.SanDiego.NCR.COM (Rick Schubert) Newsgroups: comp.std.c Subject: Re: Frustrated trying to be portable Message-ID: <1991Feb22.210428.24635@SanDiego.NCR.COM> Date: 22 Feb 91 21:04:28 GMT References: <1991Feb17.203337.20569@uokmax.ecn.uoknor.edu> <15240@smoke.brl.mil> <4188@skye.ed.ac.uk> <1991Feb20.175318.28496@zoo.toronto.edu> Sender: rock1@SanDiego.NCR.COM Reply-To: rns@tortuga.SanDiego.NCR.COM (Rick Schubert) Organization: NCR Corporation, Rancho Bernardo Lines: 32 In article <1991Feb20.175318.28496@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: >In article <4188@skye.ed.ac.uk> richard@aiai.UUCP (Richard Tobin) writes: >I haven't studied , but you need to look more closely at >before making such statements. :-) It is not possible to implement memmove(), >in particular, in portable C. (Hint: think about pointer comparisons.) I think it's been stated before that memmove() cannot be implemented in portable C, but now that I think about it, I don't think that's strictly true. It IS true that the relational operators cannot be used to compare the 2 pointer arguments to memmove() (since they may, and probably do, point to different objects), but the equality operators may be used to compare such pointers. Given the prototype: void *memmove(void *s1, const void *s2, size_t n); if the objects pointed to by |s1| and |s2| overlap, then either |s1| is one of the |n| bytes pointed at% by |s2| (in which case the copy should start at |(char *)s2 + n - 1| and proceed backward), or |s2| is one of the |n| bytes pointed at by |s1| (in which case the copy should start at |(char *)s2| and proceed forward). Each of these conditions can be determined with at most |n| pointer-equality comparisons. I'm not necessarily recommending such an implementation; it's just that it can be done portably. As far as is concerned, I don't think you can get very far without some primitive I/O facilities. Since the C language itself (outside of the library) has no I/O facilities, there is no way to do any I/O in the library without calling another function or calling a system-specific I/O routine. Or am I missing something? % Chris Torek: Did I use "point at" correctly? -- Rick Schubert (rns@tortuga.SanDiego.NCR.COM)