home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!network.ucsd.edu!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjh
- From: fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON)
- Newsgroups: comp.lang.c
- Subject: Re: strcpy implementation question
- Message-ID: <9224902.15217@mulga.cs.mu.OZ.AU>
- Date: 4 Sep 92 16:15:40 GMT
- Article-I.D.: mulga.9224902.15217
- References: <PINKAS.92Aug21114508@caraway.intel.com> <PINKAS.92Aug25163006@caraway.intel.com> <14213@goanna.cs.rmit.oz.au> <PINKAS.92Sep3173643@skywalker.intel.com>
- Sender: news@cs.mu.OZ.AU
- Organization: Computer Science, University of Melbourne, Australia
- Lines: 38
-
- pinkas@skywalker.intel.com (Israel Pinkas) writes:
-
- >ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) writes:
- >
- >RK> When is the size of the source known at compile time? Two cases:
- >RK> (a) the source is a string literal (or is a pointer whose value is known
- >RK> by constant propagation to be a specific string literal)
- >RK> (b) the code looks something like
- >RK> if (strlen(x) == 27) { /* don't change x */; strcpy(d, x); ...}
- >
- >Not quite. I said that the size of the source and destination are known,
- >not the length of the string. If the length of the string is known, and it
- >can be guaranteed to be inviolate, we only have to copy enough bytes to
- >move the string. However, strings are not inviolate, as the middle of the
- >string can be modified in ways that the compiler cannot control, such as
- >signal handlers.
-
- Actually, in a strictly conforming program, a signal handler should only
- modify variables of type "volatile sig_atomic_t". More liberally, most
- compilers will allow a signal handler to modify variables of any type, but
- they should be declared as "volatile".
-
- If the string is not declared as volatile, then the compiler should be
- able to assume that the string *is* "inviolate".
-
- >The only way a compiler can know the size of a char array is:
- > (a) It is a string literal.
- > (b) It is an array declared at compile time, with dimension(s).
-
- Well, a smart compiler might be able to determine that after
- char *s = (chart *) malloc(100);
- that s points to a char array of size 100.
-
- --
- Fergus Henderson fjh@munta.cs.mu.OZ.AU
- This .signature virus is a self-referential statement that is true - but
- you will only be able to consistently believe it if you copy it to your own
- .signature file!
-