[PATCH v5 10/15] vla: evaluate operand of sizeof if its type is a vla

Joel Brobecker brobecker@adacore.com
Wed Mar 19 15:12:00 GMT 2014


> If the operand passed to sizeof evaluates to a variable length array
> type then C99 requires that the size of the operand is evaluated at
> runtime (otherwise at compile time).
> 
> 1| int vla[n][m];
> 
> sizeof(vla[0])      // Operand type is a variable length type, size is evaluated at runtime
> sizeof(vla[0][0])   // Operand type is an int, size is evaluated at compile time 
> 
> If the expression contains a side effects it is evaluated too
> 
> sizeof(vla[i++])    // i gets modified as the operand is evaluated at runtime
> sizeof(vla[i++][0]) // no modifications, operand type evaluates to int

Very interesting! I guess whoever is writing ...

    sizeof(vla[i++][0])

... instead of ...

    sizeof(vla[i + 1][0])

... is trying to shoot himself in the foot!

Thanks for the explanation. I confess that the C RM is often somewhat
obscure to me.

> I addressed all of your issues below.

Thanks! I look forward to v6 :). Hopefully that'll be the final
iteration. FYI: I have one patch already that's dependent on your patch
series, and it has to do with handling of "ptype dynamic_sized_array"
in Ada.

Thanks!
-- 
Joel



More information about the Gdb-patches mailing list