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