On Mon, 9 Aug 2010, M. Warner Losh wrote:
In message: <86tyn4tbuc....@ds4.des.no>
Dag-Erling Sm?rgrav <d...@des.no> writes:
: Jilles Tjoelker <jil...@stack.nl> writes:
: > In other cases, I propose adding a cast to void * in between, like
: > (struct sockaddr_in *)(void *)ai->ai_addr
:
: Better to cast through uintptr_t. Perhaps we should have a
: __DECONST-like macro for this?
:
: #define __ALIGNED_CAST(t, v) ((t)(uintptr_t)(v))
__DECONST() shouldn't exist, and this would be another way to break the
warning.
I like the idea of a macro. Why is a cast through uintptr_t better?
The bugs in __DECONST() are larger than its existence:
- first, the (const void *) cast in it fails if that cast would cast
away qualifiers (mainly the volatile qualifier). Perhaps
(volatile const void *) would work better.
- next, the `(type)' cast in it fails unless `type' is precisiely `void *'
or perhaps a qualified variant of that (since [u]intptr_t only has defined
behaviour if [u]intptr_t exists and is applied to a `void *').
Casting through only uintptr_t is better because it fails in more
cases, (as for `(type)' above, but also for converting uintptr_t), and
anything that prevents use of bogus casts by making them fail is better
:-).
Bruce
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"