svn commit: r211023 - head/usr.sbin/syslogd
brde at optusnet.com.au
Tue Aug 10 11:20:41 UTC 2010
On Mon, 9 Aug 2010, M. Warner Losh wrote:
> In message: <86tyn4tbuc.fsf at ds4.des.no>
> Dag-Erling Smørgrav <des at des.no> writes:
> : Jilles Tjoelker <jilles at 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
> 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
More information about the svn-src-all