This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH v5 10/15] vla: evaluate operand of sizeof if its type is a vla
- From: Joel Brobecker <brobecker at adacore dot com>
- To: "Agovic, Sanimir" <sanimir dot agovic at intel dot com>
- Cc: "tromey at redhat dot com" <tromey at redhat dot com>, "Boell, Keven" <keven dot boell at intel dot com>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Wed, 19 Mar 2014 08:12:30 -0700
- Subject: Re: [PATCH v5 10/15] vla: evaluate operand of sizeof if its type is a vla
- Authentication-results: sourceware.org; auth=none
- References: <1391704056-25246-1-git-send-email-sanimir dot agovic at intel dot com> <1391704056-25246-11-git-send-email-sanimir dot agovic at intel dot com> <20140228173704 dot GC16479 at adacore dot com> <0377C58828D86C4588AEEC42FC3B85A7177464DE at IRSMSX105 dot ger dot corp dot intel dot com>
> 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