On Sat, Jul 28, 2012 at 1:37 PM, Stefan Stavrev <[email protected]> wrote:
> sizeof(x) = number of bytes in x.
> sizeof(float) = 4.
> sizeof(array) = number of bytes in all elements in the array.
>
> float array[10];
> sizeof(array) / sizeof(float) = sizeof(10 floats) / sizeof(1 float)
> = 10

This is all true, but it's not enough to get what you need inside the contrast
function.  (The basic problem is that C arrays decay to pointers at the drop
of a hat, or - more relevantly - when passing to a function.)

Consider:

void foo1(float array[])
{
    std::cout << sizeof(array) << "\n";
}

void foo2(float* array)
{
    std::cout << sizeof(array) << "\n";
}

These are basically equivalent, and sizeof(array) inside either of these
functions gives exactly the same result as sizeof(float*).


Try the following with your favourite compiler:

float array[10];
foo1(array);
foo2(array);


There's simply no way to avoid this problem.  (Ok ok, there is a way, but it
involves subtle and awkward messing around with several template overloads of
contrast()... let's not go there!)


~Chris
_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to