home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:12648 comp.std.c:2489
- Path: sparky!uunet!mcsun!sun4nl!and!jos
- From: jos@and.nl (Jos Horsmeier)
- Newsgroups: comp.lang.c,comp.std.c
- Subject: Re: scrcpy implementation question
- Message-ID: <3275@dozo.and.nl>
- Date: 22 Aug 92 10:45:54 GMT
- References: <PINKAS.92Aug21114508@caraway.intel.com>
- Followup-To: comp.lang.c
- Distribution: comp
- Organization: AND Software BV Rotterdam
- Lines: 43
-
- In article <PINKAS.92Aug21114508@caraway.intel.com> pinkas@caraway.intel.com (Israel Pinkas) writes:
- |
- |A compiler group working for us has told us that they plan to make the
- |following optimization for the strcpy library function:
- |
- |If the sizes of the src and dst are known at compile time (e.g. they are
- |both declared in the current file as static or auto arrays), and if the
- |addresses are aligned correctly, then strcpy will be inlined as a partially
- |unrolled loop of word moves. In order to avoid checking every byte, they
- |plan to copy past the terminator ('\0'), and copy a number of bytes equal
- |to the smaller of the src or dst.
-
- [ example why things would break, deleted ... ]
-
- |Does anybody know if strcpy is allowed to copy past the end of the string?
- |We looked at K&R2 and at the ANSI spec, but were unable to find anything
- |definite.
-
- I think it's just plain silly to implement strcpy like that. The
- standard indeed doesn't say much aobut this (simple) function:
-
- 4.11.2.3 The strcpy function
-
- The strcpy function copies the string pointed to by s2 (including the
- terminatin null character) into the array pointed to by s1. If copying
- takes place between objects that overlap, the behavior is undefined.
-
- [ end quote ]
-
- I'm willing to stick out my neck, by rephrasing the last sentence:
-
- The behavior _shall_ be defined if copying takes place between non-
- overlapping objects. (I know ice is thin here ... )
- As you said, it would certainly break lots of code (at least lots
- of my code would break.)
-
- My conclusion is that strcpy is _not_ allowed to copy past the terminating
- '\0' character, but I can't actually prove this. I'd wish the standard
- would have said something like: `if and only if copying takes place ...'
-
- kind regards,
-
- Jos aka jos@and.nl
-