This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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: [PATCH v5 10/15] vla: evaluate operand of sizeof if its type is a vla


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]