> On Mar 18, 2025, at 12:16 AM, Martin Uecker <uec...@tugraz.at> wrote:
>
> When xp->ptr is accessed, the size expression
> is evaluated and the lvalue which is formed at this point in
> time gets the type int(*)[xp->count], similar to how the size
> expression of function arguments are evaluated when the
> function is entered. The type of this expression
> then does not change anymore. You could implement it
> by rewriting it to the following.
Yes, that’s effectively similar to how the size of bounds annotations work too.
Though my question was, VLA types currently don't work this way. The size is
evaluated when it’s declared as you all discussed earlier. So do you mean you
want to fix the current behavior or make the behavior inconsistent between if
they are struct members, indirect pointers vs. local variables like below?
void test(struct X *xp) {
int len = 10;
int (*ptr)[len] = malloc(sizeof(int) * len); // (1) int (*ptr)[len] is
evaluated here and fixed.
xp->count = 100;
xp->ptr = malloc(sizeof(int) * 100); // size of xp->ptr is dynamically
evaluated with xp->count, hence, this works fine.
len = 5; // (2)
ptr = malloc(sizeof(int) * len); // size of ptr is still fixed to be (1),
so this traps at run time.
}
Yeoul