Subject: Re: __UNCONST(a)
To: Luke Mewburn <lukem@NetBSD.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 06/30/2004 08:21:42
On Jun 30, 4:44pm, lukem@NetBSD.org (Luke Mewburn) wrote:
-- Subject: Re: __UNCONST(a)
| On Tue, Jun 29, 2004 at 11:53:25PM -0400, Christos Zoulas wrote:
| | I would like to add:
| |=20
| | /* No intptr_t dependency here */
| | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
| |=20
| | in <sys/cdefs.h>
| |=20
| | Any objections?
|
| Is this to work around gcc and/or lint being overly aggressive
| in enforcing "const"ness of a type? Or bugs in those tools?
No, the tools do what they were asked for. Write strchr(),
and make it work without warnings setting WARNS=3... The problem
is const castaways are parts of the apis of functions such as
strchr(), strtol() etc:
Here's our current strchr...
char *
strchr(const char *p, int ch)
{
for (;; ++p) {
if (*p == ch) {
/* LINTED const cast-away */
return((char *)p);
}
if (!*p)
return((char *)NULL);
}
}
christos