mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Francis Moreau" <francis.moro@gmail.com>
To: "Avi Kivity" <avi@argo.co.il>
Cc: "H. Peter Anvin" <hpa@zytor.com>, linux-kernel@vger.kernel.org
Subject: Re: memparse(), simple_strtoul() prototypes...
Date: Tue, 20 Feb 2007 09:19:31 +0100	[thread overview]
Message-ID: <38b2ab8a0702200019q22bbc1b6ma0ab2771e152c288@mail.gmail.com> (raw)
In-Reply-To: <45D9AE8D.4060300@argo.co.il>

On 2/19/07, Avi Kivity <avi@argo.co.il> wrote:
> Francis Moreau wrote:
> >> > unsigned long simple_strtoul(const char *cp, char **endp,unsigned
> >> int base)
> >
> > hm, I don't get your point. I understand why we cast 'cp' into a (char
> > *) but that's not my point. My point is why aren't all function
> > parameters are not const ?
> >
>
> 'cp' can be passed as const, because simple_strtoul() does not modify
> it. 'endp' cannot be passed as const, because simple_strtoul() cannot
> know whether the caller would want to modify the string or not.
>
> Whichever way it is written, it is broken.  If changed to 'const', it
> would preclude the caller from modifying the string if one has a
> non-const string.  As written, it can silently convert a const string to
> a non-const string.  However, as written it is (a) standard conforming,
> and (b) more useful.
>

ok I think I finally got it and I agree that both ways are broken.

Maybe changing simple_strtoul() prototype as follow would be better ?

int simple_strtoul(const char *cp,  unsigned long *value, unsigned base)

the function would return the number of parsed char, and 'value' would
be the result.
-- 
Francis

      reply	other threads:[~2007-02-20  8:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-18 16:04 Francis Moreau
2007-02-19  0:30 ` H. Peter Anvin
2007-02-19 13:03   ` Francis Moreau
2007-02-19 14:05     ` Avi Kivity
2007-02-20  8:19       ` Francis Moreau [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38b2ab8a0702200019q22bbc1b6ma0ab2771e152c288@mail.gmail.com \
    --to=francis.moro@gmail.com \
    --cc=avi@argo.co.il \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®