home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / c / 12934 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  2.1 KB

  1. Xref: sparky comp.lang.c:12934 comp.std.c:2535
  2. Newsgroups: comp.lang.c,comp.std.c
  3. Path: sparky!uunet!pipex!demon!edscom.demon.co.uk!kevin
  4. From: kevin@edscom.demon.co.uk (Kevin Broadey)
  5. Subject: Re: scrcpy implementation question
  6. In-Reply-To: pinkas@caraway.intel.com's message of 21 Aug 92 19:45:08 GMT
  7. Message-ID: <KEVIN.92Aug28180736@runningbear.edscom.demon.co.uk>
  8. Sender: kevin@edscom.demon.co.uk (Kevin Broadey)
  9. Organization: EDS-Scicon, Milton Keynes, UK
  10. References: <PINKAS.92Aug21114508@caraway.intel.com>
  11. Distribution: comp
  12. Date: Fri, 28 Aug 1992 18:07:36 GMT
  13. Lines: 36
  14.  
  15. >>>>> In article <PINKAS.92Aug21114508@caraway.intel.com>, "ip" ==
  16. >>>>> pinkas@caraway.intel.com (Israel Pinkas) writes:
  17. ip> Nntp-Posting-Host: caraway
  18.  
  19.  
  20. ip> A compiler group working for us has told us that they plan to make the
  21. ip> following optimization for the strcpy library function:
  22.  
  23. ip> If the sizes of the src and dst are known at compile time (e.g. they are
  24. ip> both declared in the current file as static or auto arrays), and if the
  25. ip> addresses are aligned correctly, then strcpy will be inlined as a partially
  26. ip> unrolled loop of word moves.  In order to avoid checking every byte, they
  27. ip> plan to copy past the terminator ('\0'), and copy a number of bytes equal
  28. ip> to the smaller of the src or dst.
  29.  
  30. I'm no compiler expert but I'm a seasoned C-hacker, so here's my opinion
  31. after 30 seconds consideration:-
  32.  
  33. The important point to note is that the clever strcpy code only comes
  34. into play if the *sizes* of src and dst are known at compile-time, in
  35. which case the code simplifies to:-
  36.  
  37.     memcpy (dst, src, min (sizeof (src), sizeof (dst)))
  38.  
  39. Furthermore, the clever strcpy is only used when the *alignment* is
  40. favourable, so you're never going to copy outside your reserved memory
  41. area.
  42.  
  43. This does give different behaviour if the source string overflows dst,
  44. but who in their right mind *intentionally* writes code like that?
  45.  
  46. --
  47. Kevin Broadey <kbroadey@edscom.demon.co.uk>
  48. EDS-Scicon, Wavendon Tower, Wavendon, Milton Keynes, MK17 8LX, England.
  49. Phone: +44 908 284198 (direct) or +44 908 585858 ext 4198
  50. These opinions are mine: others available on request.
  51.