h5part AT lists.psi.ch
Subject: H5Part development and discussion
List archive
- From: Achim Gsell <achim.gsell AT psi.ch>
- To: Mark Howison <MHowison AT lbl.gov>
- Cc: h5part AT lists.psi.ch
- Subject: [H5part] Re: error handling in H5hut
- Date: Fri, 2 Jul 2010 09:02:24 +0200
- List-archive: <https://lists.web.psi.ch/pipermail/h5part/>
- List-id: H5Part development and discussion <h5part.lists.psi.ch>
On Jul 1, 2010, at 10:44 PM, Mark Howison wrote:
> Hmm, so I'm confused about how the (ptr_diff) cast will work... if
> h5priv_alloc returns
>
> return (void*)(H5_ERR);
>
> isn't the cast to void* going to convert -1 to some bogus non-negative
> value? Why would (ptr_diff) convert it back to -1?
May be (void*)((char*)NULL + H5_ERR) is more save. But (void*)(H5_ERR) should
be save on all two-complement systems.
The 32bit two-complement representation of -1 is 0xffffffff. This is a valid
value for a pointer, even it will never be used. So the cast of H5_ERR to
void* gives 0xffffffff, which is a valid pointer difference. ptrdiff_t is a
signed integral type, and as such can be casted to compatible fundamental
data types. So
(int64_t)(ptrdiff_t)(void*)(H5_ERR) =
(int64_t)(ptrdiff_t)(void*)(-1) =
(int64_t)(ptrdiff_t)(0xffffffff) =
(int64_t)(ptrdiff_t)(-1) =
(int64_t)(-1)
Achim
- [H5part] Re: error handling in H5hut, Achim Gsell, 07/01/2010
- Message not available
- [H5part] Re: error handling in H5hut, Achim Gsell, 07/02/2010
- Message not available
Archive powered by MHonArc 2.6.19.