[Insight-developers] Dashboard Cleanup: mini0.nlm MacOSX-cross-rosetta : 50 tests failing

Kevin H. Hobbs hobbsk at ohiou.edu
Thu Jan 28 13:59:27 EST 2010


On 01/28/2010 01:31 PM, Michel Audette wrote:
> Hi Luis,
> 
> your value *d* in the bolded part of your suggested code is undefined
> when used as an index. It has to be as
> d = dim - 1;
> l = coord[d];
> d--;
> for coord to have a valid index, doesn't it?
> 
> I propose... (extra check on validity of index d)
> #define NRRD_INDEX_GEN(I, coord, size, dim)   \
> int d;                                                                 \
> d = (dim) - 1;                                                      \
> if ( (d) >= 0 )                                                      \
> {                                                                       \
>   (I) = (coord)[d];                                                \
>   d--;                                                                 \
>   while( d >= 0 )                                                 \
>   {                                                                     \
>   (I) = (coord)[d] + (size)[d] * (I);                          \
>   d--;                                                                 \
>   }                                                                     \
> }                                                                       \
> and to take out the pragmas.
> 
> Seem reasonable?
> 
> Michel
> 

I like your check for d >= 0. Nothing will happen if dim = 1 where I'm
guessing the present code would do something undefined if dim == 1. Does
NRRD even deal with 1-d things?

The only other thing that jumps to mind is that since this is a macro in
C we might want to follow the lead of the original header and wrap the
whole thing up in a do{...}while(0) I guess this is to avoid redefining
d or declaring d in the middle of a block of code. This will probably
make the code easier to digest for older compilers but I'm by no means
an expert here.

Instead of do{...}while(0) could it be if ( dim >= 1 ){...} else {...} ?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20100128/2aa0667c/attachment.pgp>


More information about the Insight-developers mailing list