Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 10 Aug 2010 21:20:27 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        "M. Warner Losh" <imp@bsdimp.com>
Cc:        src-committers@FreeBSD.org, jilles@stack.nl, svn-src-all@FreeBSD.org, olli@fromme.com, svn-src-head@FreeBSD.org, des@des.no
Subject:   Re: svn commit: r211023 - head/usr.sbin/syslogd
Message-ID:  <20100810210449.H10110@delplex.bde.org>
In-Reply-To: <20100809.095007.4959786895405928.imp@bsdimp.com>
References:  <20100808.153608.1142818667055052395.imp@bsdimp.com> <20100808220631.GA86477@stack.nl> <86tyn4tbuc.fsf@ds4.des.no> <20100809.095007.4959786895405928.imp@bsdimp.com>

next in thread | previous in thread | raw e-mail | index | archive | help
  This message is in MIME format.  The first part should be readable text,
  while the remaining parts are likely unreadable without MIME-aware tools.

--0-2134441558-1281439227=:10110
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed
Content-Transfer-Encoding: QUOTED-PRINTABLE

On Mon, 9 Aug 2010, M. Warner Losh wrote:

> In message: <86tyn4tbuc.fsf@ds4.des.no>
>            Dag-Erling Sm=F8rgrav <des@des.no> writes:
> : Jilles Tjoelker <jilles@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 defin=
ed
   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
--0-2134441558-1281439227=:10110--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100810210449.H10110>