[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
small header change to correct an unnecessary compiler warning
From: |
Agthorr |
Subject: |
small header change to correct an unnecessary compiler warning |
Date: |
Wed, 11 Jul 2001 16:05:46 -0400 |
User-agent: |
Mutt/1.2.5i |
I'm running GNU libc version 2.2.3.
I recently noticed that the function strtol() is declared as follows:
extern long int strtol (__const char *__restrict __nptr,
char **__restrict __endptr, int __base) __THROW;
This causes a warning to be generated unnecessarily for the following
perfectly legimate code:
------------------------------------------------------------------------
#include <stdlib.h>
int main(void) {
char bloop[] = "123";
const char *foo = bloop;
strtol (foo, &foo, 0);
return 0;
}
------------------------------------------------------------------------
The warning is:
test.c: In function `main':
test.c:7: warning: passing arg 2 of `strtol' from incompatible pointer type
If you changed the declaration of __endptr as show below, it would
eliminate this warning, without breaking any existing code:
__const char **__restrict __endptr
This can be guaranteed not to break anything, since casts from
"char **" to "const char **" are implicit. Also, this won't break
strtol(), since it modifies *__endptr, but never **__endptr.
In fact, although "const" is usually associated with being more
restrictive, this would allow a superset of code to compile without
warnings.
strtoul(), strtod(), and similar functions suffer from the same problem.
It's a small complaint, but it's also easy to correct!
-- Agthorr
- small header change to correct an unnecessary compiler warning,
Agthorr <=