<br>Hi Mike,<br><br>OffsetValueType is certainly not intended to be a Pointer,<br>but indeed to be the difference between two pointers.<br><br>The typical use of OffsetValueType is to locate a pixel<br>in the block of memory of an image:<br>
<br> OffsetValueType offset = 555;<br> image->GetBuffer() + offset;<br><br>The other use of OffsetValueType is to be the components<br>of the differences between two indices, which by extension<br>
should make us consider using ptrdiff_t also as the component<br>type of the itk::Index and the itk::Size, since it is a valid use<br>to allocate a 1D image of 10Gb.<br><br>I'm not sure that the argument of whether some programmer<br>
may get confused, should take precedence over the argument<br>of what is the correct type to use.<br><br>The first problem gets solved with three lines of comments<br>in the declaration of<br><br> /** Here we explain why... */<br>
typedef ptrdiff_t OffsetValueType<br><br>Following basic practices of Generic Programming, in all<br>subsequent ITK code, we should use the type "OffsetValueType"<br>and there is no need to expose what OffsetValueType actually is.<br>
<br><br>Users that digg deep into the code will be already confused<br>by the fact that different platforms define "int" and "long" in<br>different ways. What is interesting about ptrdiff_t is that is<br>
clearly defined in a platform-independent way.<br><br><br>The best way to protect people from ignorance,<br>is to actually educate them. :-)<br><br><br> Luis<br><br><br>--------------------------------------------------------------------------------------<br>
<div class="gmail_quote">On Sat, Jul 11, 2009 at 8:50 AM, Mike Jackson <span dir="ltr"><<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I think the only thing I have against using ptrdiff_t is that it<br>
doesn't describe exactly what you are wanting in a type. ptrdiff_t is<br>
the result of subtraction between two _pointers_. Is OffsetValueType<br>
really a Pointer or an index into an array? I think if programmers<br>
started digging when debugging and saw ptrdiff_t then that might be<br>
confusing to them as they might start thinking that they can cast an<br>
OffsetValueType to a pointer and start doing pointer manipulations on<br>
it.<br>
It seems to me that OffsetValueType is just that, a _value_, and<br>
not a pointer. Also, do we fully understand how ptrdiff_t is defined<br>
on all the platforms that ITK runs on? Can we be sure we take that<br>
into account properly? In comparison we know _exactly_ how it behaves<br>
because we would be using either "int" or "long long int" which also<br>
has the advantage of describing exactly what we need, a plain old<br>
signed integer. Again, when new ITK programmers start digging to find<br>
out what OffsetValueType and come up with a plain old integer there<br>
most likely will not be any misunderstanding about the type.<br>
<br>
Mike Jackson<br>
<div><div></div><div class="h5"><br>
On Sat, Jul 11, 2009 at 7:02 AM, Luis Ibanez<<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>> wrote:<br>
><br>
> What's wrong with using : ptrdiff_t ?<br>
><br>
><br>
> Luis<br>
><br>
><br>
> -----------------------------------------------------------<br>
> On Fri, Jul 10, 2009 at 8:34 PM, Mike Jackson <<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>><br>
> wrote:<br>
>><br>
>> Probably should have googled that first. Seems to be a POSIX extension<br>
>> so probably isn't that portable.<br>
>><br>
>> From an earlier email:<br>
>> ------<br>
>> On recent realization:<br>
>><br>
>> "size_t" is unsigned :-/<br>
>><br>
>> and we need the OffsetValueType to be signed,<br>
>> since we use it to compute differences...<br>
>> ------<br>
>> so why doesn't ITK just define it to int or long long int depending on<br>
>> the size of size_t? That test could be run during CMake time like all<br>
>> the others?<br>
>><br>
>> #if size_of_size_t == 4<br>
>> typedef signed int OffsetValueType;<br>
>> #elif size_of_size_t == 8<br>
>> typedef signed long long int OffsetValueType;<br>
>> #endif<br>
>><br>
>> Of course we would probably want to use the predefined 64 bit type<br>
>> that the ITK/CMake tests come up with: __int64, _int64_t, int64_t or<br>
>> whatever they are..<br>
>><br>
>> Just my thoughts?<br>
>> Mike<br>
>><br>
>> On Fri, Jul 10, 2009 at 8:23 PM, Mike<br>
>> Jackson<<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>> wrote:<br>
>> > Is there a "ssize_t" type? Or is that some contrived type on some of<br>
>> > the projects that I work on?<br>
>> ><br>
>> > Mike<br>
>> ><br>
>> > On Fri, Jul 10, 2009 at 6:29 PM, Luis Ibanez<<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> On recent realization:<br>
>> >><br>
>> >> "size_t" is unsigned :-/<br>
>> >><br>
>> >> and we need the OffsetValueType to be signed,<br>
>> >> since we use it to compute differences...<br>
>> >><br>
>> >> It seems that what we need is the type<br>
>> >><br>
>> >> "ptrdiff_t"<br>
>> >><br>
>> >> which is supposed to represent the differences<br>
>> >> between two pointers, and therefore should be<br>
>> >> capable of measuring distances between any<br>
>> >> two locations in memory.<br>
>> >><br>
>> >> I'm now rerunning the Experimental with<br>
>> >> "ptrdiff_t" instead of "size_t".<br>
>> >><br>
>> >><br>
>> > Luis<br>
>> ><br>
><br>
</div></div><div><div></div><div class="h5">_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at: <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</div></div></blockquote></div><br>