Re: memparse(), simple_strtoul() prototypes...

2007-02-20 Thread Francis Moreau

On 2/19/07, Avi Kivity <[EMAIL PROTECTED]> 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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: memparse(), simple_strtoul() prototypes...

2007-02-20 Thread Francis Moreau

On 2/19/07, Avi Kivity [EMAIL PROTECTED] 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
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: memparse(), simple_strtoul() prototypes...

2007-02-19 Thread Avi Kivity

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.


--
error compiling committee.c: too many arguments to function

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: memparse(), simple_strtoul() prototypes...

2007-02-19 Thread Francis Moreau

Hi,

On 2/19/07, H. Peter Anvin <[EMAIL PROTECTED]> wrote:

Francis Moreau wrote:
> Hi,
>
> I must miss something...
>
> Looking at these prototypes
>
> unsigned long simple_strtoul(const char *cp, char **endp,unsigned int base)
> unsigned long long memparse (char *ptr, char **retptr)
>
> I'm really wondering why not all parameters are not all 'const'. None
> of these functions modify any pointer containts. And simple_strtoul()
> ends up doing sometghing like:
>
> if (endp)
> *endp = (char *)cp;
>
> Could anyone shed some light ?

The C standard behaves like that, too, mostly because C doesn't have a
way to say "X is const iff Y is const" (unlike C++, btw.)



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 ?

--
Francis
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: memparse(), simple_strtoul() prototypes...

2007-02-19 Thread Francis Moreau

Hi,

On 2/19/07, H. Peter Anvin [EMAIL PROTECTED] wrote:

Francis Moreau wrote:
 Hi,

 I must miss something...

 Looking at these prototypes

 unsigned long simple_strtoul(const char *cp, char **endp,unsigned int base)
 unsigned long long memparse (char *ptr, char **retptr)

 I'm really wondering why not all parameters are not all 'const'. None
 of these functions modify any pointer containts. And simple_strtoul()
 ends up doing sometghing like:

 if (endp)
 *endp = (char *)cp;

 Could anyone shed some light ?

The C standard behaves like that, too, mostly because C doesn't have a
way to say X is const iff Y is const (unlike C++, btw.)



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 ?

--
Francis
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: memparse(), simple_strtoul() prototypes...

2007-02-19 Thread Avi Kivity

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.


--
error compiling committee.c: too many arguments to function

-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: memparse(), simple_strtoul() prototypes...

2007-02-18 Thread H. Peter Anvin

Francis Moreau wrote:

Hi,

I must miss something...

Looking at these prototypes

unsigned long simple_strtoul(const char *cp, char **endp,unsigned int base)
unsigned long long memparse (char *ptr, char **retptr)

I'm really wondering why not all parameters are not all 'const'. None
of these functions modify any pointer containts. And simple_strtoul()
ends up doing sometghing like:

if (endp)
*endp = (char *)cp;

Could anyone shed some light ?


The C standard behaves like that, too, mostly because C doesn't have a 
way to say "X is const iff Y is const" (unlike C++, btw.)


-hpa
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


memparse(), simple_strtoul() prototypes...

2007-02-18 Thread Francis Moreau

Hi,

I must miss something...

Looking at these prototypes

unsigned long simple_strtoul(const char *cp, char **endp,unsigned int base)
unsigned long long memparse (char *ptr, char **retptr)

I'm really wondering why not all parameters are not all 'const'. None
of these functions modify any pointer containts. And simple_strtoul()
ends up doing sometghing like:

if (endp)
*endp = (char *)cp;

Could anyone shed some light ?
--
Francis
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


memparse(), simple_strtoul() prototypes...

2007-02-18 Thread Francis Moreau

Hi,

I must miss something...

Looking at these prototypes

unsigned long simple_strtoul(const char *cp, char **endp,unsigned int base)
unsigned long long memparse (char *ptr, char **retptr)

I'm really wondering why not all parameters are not all 'const'. None
of these functions modify any pointer containts. And simple_strtoul()
ends up doing sometghing like:

if (endp)
*endp = (char *)cp;

Could anyone shed some light ?
--
Francis
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: memparse(), simple_strtoul() prototypes...

2007-02-18 Thread H. Peter Anvin

Francis Moreau wrote:

Hi,

I must miss something...

Looking at these prototypes

unsigned long simple_strtoul(const char *cp, char **endp,unsigned int base)
unsigned long long memparse (char *ptr, char **retptr)

I'm really wondering why not all parameters are not all 'const'. None
of these functions modify any pointer containts. And simple_strtoul()
ends up doing sometghing like:

if (endp)
*endp = (char *)cp;

Could anyone shed some light ?


The C standard behaves like that, too, mostly because C doesn't have a 
way to say X is const iff Y is const (unlike C++, btw.)


-hpa
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/