Subject: Re: __UNCONST(a)
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@zoulas.com>
List: tech-userlevel
Date: 06/30/2004 23:04:51
In article <20040630204857.GW357@snowdrop.l8s.co.uk>,
David Laight <david@l8s.co.uk> wrote:
>On Tue, Jun 29, 2004 at 11:53:25PM -0400, Christos Zoulas wrote:
>> 
>> I would like to add:
>> 
>>     /* No intptr_t dependency here */
>>     #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a))
>> 
>> Any objections?
>
>Why not:
>
>#define __UNCONST(a) ((void *)(((const char *)(a) - (const char *)0) +
>(char *)0))
>
>Which does away with requiring an integral type.
>
>Or better still the inline function:
>
>static inline void *
>__UNCONST(const void *a)
>{
>    return ((const char *)a - (const char *)0) + (char *)0;
>}
>
>Which will validate that the supplied parameter is a pointer type.

I like the pointer arithmetic idea...

christos