Subject: Re: -Wcast-qual and assignement to strucutres
To: None <tech-kern@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 02/12/2006 22:50:10
> I've a problem with -Wcast-qual: [...a writev-style use of struct
> iovec...]
Yes. struct iovec, in write-style uses, is incompatible with proper
const poisoning (not terribly surprising, since it predates const).
The const-clean way is to have a constified version which is used by
write-style calls and a non-constified version for read-style or
read/write calls - but that is difficult for backward-compatability
reasons.
Personally, I just strip the qualifiers, typically with something like
void *dequal(const volatile void *arg)
{
return(((const volatile char *)arg)-(const volatile char *)0)+(char *)0);
}
which is not really portable, but close enough for me. (To be properly
portable you'd have to do something like
void *dequal(const volatile void *arg)
{
void *rv;
bcopy(&arg,&rv,sizeof(void *));
return(rv);
}
but I usually don't think calling the external routine is worth the
additional portability, even if it does get inlined at least some of
the time. The __UNCONST christos recommended involves another
nonportability, at least in its 3.0 implementation, namely that
assuming that casting to unsigned long and back doesn't destroy
information; I may start using that myself, since I suspect that's at
least as portable as the arithmetic-on-nil-pointers way.)
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B