With regards to this current discussion, has anyone given thought to the
fact that if the const string address being passed into a function with a
const typed parameter resides within a memory page marked as ReadOnly the
constified function will GP should it attempt to write to that page?  I'm
not sure of the behavior of every OS or compiler optimization or memory
layout currently in existence but the const modifier means just that: the
const address given to a function points to memory that will not, ever, be
modified.  Functions that need to make temporary modifications within such a
string must make a local copy first.
My .02 cents worth...

----- Original Message -----
From: Lutz Jaenicke <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, November 08, 2000 10:08 AM
Subject: Re: Constification


> On Wed, Nov 08, 2000 at 04:01:13PM +0100, Richard Levitte - VMS Whacker
wrote:
> > So, either:
> >
> >     const char *correct_strstr(const char *s1, const char *s2)
> >     {
> > return strstr(s1, s2);
> >     }
> >
> > or:
> >
> >     char *correct_strstr(char *s1, const char *s2)
> >     {
> > return strstr(s1, s2);
> >     }
> >
> > Is that right?  Both of those have problems.  The first because you
> > can't manipulate the result even if the strings you gave from the
> > start are non-const, and the second because you can't give it a 'const
> > char *' as first argument...
>
> HP-UX says:
> char *strstr(const char *s1, const char *s2);
>
> I read this: s1 and s2 are passed to strstr(). strstr() will not modify
> the locations s1 and s2 are pointing to, so the optimizer may safely
> assume that they have not been changed after the call to strstr().
>
> That does not make any statement about what the calling function does
> with s1 (and hence the return value _must_not_ be "const char *").
>
> Sorry, couldn't resist :-)
> Lutz
> --
> Lutz Jaenicke                             [EMAIL PROTECTED]
> BTU Cottbus               http://www.aet.TU-Cottbus.DE/personen/jaenicke/
> Lehrstuhl Allgemeine Elektrotechnik                  Tel. +49 355 69-4129
> Universitaetsplatz 3-4, D-03044 Cottbus              Fax. +49 355 69-4153
> ______________________________________________________________________
> OpenSSL Project                                 http://www.openssl.org
> Development Mailing List                       [EMAIL PROTECTED]
> Automated List Manager                           [EMAIL PROTECTED]

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to