Re: Is it conformant to substract two pointer-to-void ?
- From: Francois Grieu <fgrieu@xxxxxxxxx>
- Date: Thu, 13 Mar 2008 00:49:57 -0700 (PDT)
On 12 mar, 22:36, Eric Sosman <Eric.Sos...@xxxxxxx> wrote:
Francois Grieu wrote:#define CHK_PTR_TYPE(ptr,basetype) (1?(ptr):((ptr)-(basetype*)(ptr))+
Why do you *want* this to work?
My application includes the following:
(ptr))
and I am concerned that this wont reliably work when basetype is
void or const void
I guess that by "work" you mean "produce a diagnostic if
the type of *ptr is not compatible with basetype?"
Yes, that's my goal.
As written, the test should elicit a diagnostic if the
types are incompatible (which is what I think you want), or
if ptr is void* or if basetype is void (which I think you'd
regard as false positives).
Yes.
I don't understand what the addition at the end is for
It is here to make the expression correct. (ptr)-(basetype*)(ptr)
is a ptrdiff_t and we need to add a ptr to make that
compatible with a ptr, on the left side of the :
If you'd be happy with a slightly different test (compatibility
of ptr with basetype* instead of *ptr with basetype), you might
try
#define CHK_PTR_TYPE(ptr,basetype) \
(1 ? (ptr) : (basetype*)(ptr))
... the idea being that the second and third operands of ?:
must be of compatible pointer types (6.5.15p3), and the
compiler must diagnose a constraint violation.
Indeed that SHOULD do the job. <OT> I'll check with the
various compilers that I target, but I'm a bit pessimistic,
I think I remember one of them is hapy with mixing int and
pointers on each side of : </OT>
Francois Grieu
.
- References:
- Is it conformant to substract two pointer-to-void ?
- From: Francois Grieu
- Re: Is it conformant to substract two pointer-to-void ?
- From: Keith Thompson
- Re: Is it conformant to substract two pointer-to-void ?
- From: Francois Grieu
- Re: Is it conformant to substract two pointer-to-void ?
- From: Eric Sosman
- Is it conformant to substract two pointer-to-void ?
- Prev by Date: Received file doesnt display contents properly.
- Next by Date: Re: Is it conformant to substract two pointer-to-void ?
- Previous by thread: Re: Is it conformant to substract two pointer-to-void ?
- Next by thread: Re: Is it conformant to substract two pointer-to-void ?
- Index(es):
Relevant Pages
|
|