[Bf-committers] cast from flat arrays to multidimensional arrays

Ton Roosendaal bf-committers@blender.org
Mon, 23 Jun 2003 21:44:20 +0200


Hi,


> cspadd demands a short cont[][3], and a char* is passed-->warning!
> warning: passing arg 2 of `cspadd' from incompatible pointer type

I think it's a typo, you mean short* ?

> It is simple to rewrite cspadd :
>
> static void cspadd(short *buf, short *cont, unsigned char *rect, int x)
> {
>    short i;
>    for (;x>0;x--){
>        i = *(rect);
>        rect += 4;
>        buf[0] += cont[i*3];
>        buf[1] += cont[i*3+1];
>        buf[2] += cont[i*3+2];
>        buf += 3;
>    }
> }

Looks good!

> The programmer clearly noticed that multi-dimensionnal arrays, in C,
> are represented like flat arrays, and uses flat arrays as
> multidimensional arrays.

I think with a "flat array" you mean a one dimensional array?

This code comes from the very early days, when our Irix cc compiler  
didn't complain when casting from a multi-dimensional array to pointer,  
like you noticed.
You can find this still all over Blender, especially for matrix  
calculus.

The simple problem is, that C doesn't provide a "pointer to [3][3]  
array" or so... you cannot cast it either, and the warning remains  
active. And that whilst it's perfectly OK working code. A "short  
cont[][3]" for me still is a way to make a pointer to such an array.

I think it's more a case of "not done" than "wrong". So we can better  
agree not to introduce such code in new modules or additions to  
Blender. Replacing all matrix code calls in old Blender code is a very  
tedious task. And won't make the code readable either. Or easily  
introduce new bugs

I rather see a means to disable this warning in gcc (and other  
compilers). I prefer to get rid of warnings too! :)

-Ton-



>
>
> I'm willing to get rid of the zillions of warnings generated by the
> compilation.
> Should these modifications be commited, or am I missing a point?
>
> Tks in advance.
>
>
>
>
>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers@blender.org
> http://www.blender.org/mailman/listinfo/bf-committers
>
>
------------------------------------------------------------------------ 
--
Ton Roosendaal  Blender Foundation ton@blender.org  
http://www.blender.org