On Sat, 6 May 2006, Mike Stump wrote:

> I'll entertain pointers to VLA/VM and [*] bugs for C, please send me pointers
> to reports in bugzilla.
> 
> Thanks.
> 
> I know about http://gcc.gnu.org/PR25802

Bugs 19771, 7948, 18740 (in general, look at the bugs on which bug 16989 
depends).  The question of when exactly an array size expression is 
evaluated requires careful thought and design to ensure it is always done 
at the right time, the other issues should be easier to resolve.

> I also would like to know what people think the standard (c99) says about:
> 
> void foo4(int o[*][4]) { }
> void foo5(int o[4][*]) { }

Invalid.

> void foo6(int (*o)(int p[*])) { }

Valid.

Function prototype scope is defined in 6.2.1#4.


More examples:

void foo(int a, int b[*][*], int c[static sizeof(*b)]);

is valid code, though what size is relevant for the [static] is more 
obscure.  sizeof a [*] array returns an indeterminate nonconstant value of 
type size_t, which can be used in expressions just like other values of 
type size_t.

void foo(int x[sizeof(int (*)[*])]);

should probably be considered invalid, as should

void foo(int [*]);

([*] being used in a type that's not a declaration).  (I'm not aware of 
anything to contradict Nick Maclaren's interpretation 
<http://groups.google.com/group/comp.std.c/msg/b01f49f6c9c0039a> here.)

The example I gave in WG14 reflector message 10731 ought probably to be 
invalid or at least undefined behavior at runtime - the latter is probably 
the best interpretation for now, since I haven't written or submitted a DR 
for that case.  To quote my message:

Consider the code

        int a, b, c, d, e, f;
        void *p1(void), *p2(void), *p3(void);
        int c1(void), c2(void);
        int d1(void), d2(void), d3(void);
        int z1(void), z2(void), z3(void);

        int
        h(void)
        {
          int r = (c1()
                   ? (z1(), (int (*(*(*)[d1()])[])[])p1())
                   : (c2()
                      ? (z2(), (int (*(*(*)[])[d2()])[])p2())
                      : (z3(), (int (*(*(*)[])[])[d3()])p3())
                     )
                  )[a][b][c][d][e][f];
          return r;
        }

        The outer conditional expression has a type which may informally be 
        described as "pointer to arrays [d1()] of pointers to arrays [d2()] of 
        pointers to arrays [d3()] of ints", by the composite type rules applied 
to 
        conditional expressions.  But when the expression is executed, all 
three 
        dimensions are needed to evaluate the [a][b][c][d][e][f] array 
reference, 
        but only one of the dimensions appears in an expression which should be 
        evaluated according to the rules for evaluation of conditional 
        expressions.  Furthermore, the return value of d2() may depend on the 
        prior calls to c2() and z2() in that part of the conditional 
expression, 
        so if c1() returns nonzero it might not suffice simply to evaluate d2() 
        and d3() as well as d1(); c2(), z2() and z3() would also need to be 
        evaluated.

        Which functions should be called when in the evaluation of the above 
        expression?  Or, should such constructs be disallowed and how would we 
        define what the invalid constructs are?

        (Much the same issue arises with compound literals of VM type as does 
with 
        casts to VM type.)

See also my DRs 311, 312, 313 (which deal with rather simpler cases).  
There's also a pre-DR I haven't submitted to WG14, 
<http://www.srcf.ucam.org/~jsm28/gcc/pre-dr-14.txt>.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    [EMAIL PROTECTED] (personal mail)
    [EMAIL PROTECTED] (CodeSourcery mail)
    [EMAIL PROTECTED] (Bugzilla assignments and CCs)

Reply via email to