[Insight-developers] Analyze writer header size incorrect on 64-bit system

Sean McBride sean at rogue-research.com
Tue Jul 24 13:10:15 EDT 2007


On 7/24/07 11:35 AM, kent williams said:

>Well you're right in that this code wouldn't work if sizeof int was 64 bit.
>
>But there _should_ be some solution available.  The most obvious would be to
>define the header in terms of data types of known size, EG int16 int32
>long64, etc.  

Yes, that would be ideal.  Additionally, one needs to force structure
alignment, for example by using '#pragma pack'.  Alas, different
compilers do this differently, but that's not insurmountable.

>Writing out binary structures to files isn't an isolated design failing of
>NIfTI and ANALYZE file formats

Very true.

>, and there's a tradition going back as far as
>I've been programming (1982?) of carefully defining data structures so they
>can be written and read directly to/from disk.
>
>My point being, there was no 'luck' involved -- the structure was laid out
>such that it would get read and written correctly on nearly all current
>platforms.

No, the structure is _not_ carefully laid out, or at least not carefully
enough.  :)  You said so yourself above: "this code wouldn't work if
sizeof int was 64 bit".  In other words, yes, luck is involved.  It is
perfectly valid for a C compiler to make 'int' 64 bit.  You're right of
course that it will work on nearly all current platforms.

Computer science has advanced a lot since 1982, following traditions
from back then is probably not so useful these days.  :)

>It should be mentioned as well that ITK uses third party code for NIfTI
>reading/writing -- no ITK develper wrote this code. Hans happens to be part
>of the developer group for NIfTI, so if we come up with a solution to this
>64-bit header problem, we can push it back to the official NIfTI library.

Well, personally I favour the types defined by C99 in <stdint.h>, see:
<http://en.wikipedia.org/wiki/Stdint.h>

-- 
____________________________________________________________
Sean McBride, B. Eng                 sean at rogue-research.com
Rogue Research                        www.rogue-research.com 
Mac Software Developer              Montréal, Québec, Canada




More information about the Insight-developers mailing list