Re: Infinite loop in dcraw with current GCC versions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28/02/15 16:27, Manuel López-Ibáñez wrote:
> cam_xyz[0] is type 'double [3]', thus I don't think you should cast it
> to 'double *', but in this respect I am just going by intuition, not
> by an actual reference to the standard. On the other hand,
> &cam_xyz[0][0] should have type 'double *', and the standard does say
> that the data is contiguously allocated, yet the c-faq says that
> ((double *)(&cam_xyz[0][0]))[j] "is not in strict conformance with the
> ANSI C Standard; according to an official interpretation"
> (http://c-faq.com/aryptr/ary2dfunc2.html), although without a
> reference to the standard, I have no idea what that means.

Here we go.  :-)

ANSI defines E1[E2] as

    (*((E1)+(E2)))

and (therefore) cam_xyz[i][j] as

    *((*(cam_xyz+i))+j)


ISO/IEC 9899:1999, 6.5.1 Primary expressions:

"Successive subscript operators designate an element of a
multidimensional array object. If E is an n-dimensional array (n ≥ 2)
with dimensions i × j × . . . × k, then E (used as other than an
lvalue) is converted to a pointer to an (n − 1)-dimensional array with
dimensions j × . . . × k. If the unary * operator is applied to this
pointer explicitly, or implicitly as a result of subscripting, the
result is the pointed-to (n − 1)-dimensional array, which itself is
converted into a pointer if used as other than an lvalue."

Therefore the result of the inner

    *(cam_xyz+i)

is a one-dimensional array.  You have no permission to dereference
beyond the end of that array, and any attempt to do so is UB.

Andrew.





[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux