This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Infinite loop in dcraw with current GCC versions


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]