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 Tue, Mar 24, 2009 at 10:46 AM, Dave Korn
<dave.korn.cygwin@googlemail.com> wrote:
> Brian Ellis wrote:
>> struct dynamic { int size; int array[]; };
>
>> int main() { struct dynamic * pBadness = ?((struct dynamic *) malloc(
>> sizeof(int) * 3) );
>
>> dont_do_this( *pBadness );
>
>
> ?Are you even allowed to dereference a pointer to a struct containing a VLA?
> ?Should it be treated like an incomplete type in this respect?
>

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.


H.J.


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