This is the mail archive of the gcc@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: Should structure with flexible array be allowed to be passed by value?


On Wed, 25 Mar 2009, H.J. Lu wrote:

> gcc.c-torture/compile/pr16566-2.c has
> 
> ---
> struct A
> {
>     int i;
>     int x[];
> };
> 
> int foo(struct A a)
> {
>     return (a,a).x[0];
> }
> ---
> 
> foo will return a random number. I don't think it should be allowed.

This is a perfectly ordinary case of accessing outside array bounds, 
undefined behavior at runtime if the code in question is ever executed but 
OK in a program as long as the dereference isn't executed.

-- 
Joseph S. Myers
joseph@codesourcery.com


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