diff --git a/tools/qfcc/source/expr.c b/tools/qfcc/source/expr.c index 609d602e0..74a81369f 100644 --- a/tools/qfcc/source/expr.c +++ b/tools/qfcc/source/expr.c @@ -2537,8 +2537,9 @@ cast_expr (type_t *type, expr_t *e) && !(is_scalar (type) && is_scalar (e_type))) { return cast_error (e, e_type, type); } - if (is_array (e_type)) - return address_expr (e, 0, 0); + if (is_array (e_type)) { + return address_expr (e, 0, type->t.fldptr.type); + } if (is_constant (e) && is_scalar (type) && is_scalar (e_type)) { ex_value_t *val = 0; if (e->type == ex_symbol && e->e.symbol->sy_type == sy_const) { diff --git a/tools/qfcc/test/structarray.r b/tools/qfcc/test/structarray.r index d6c67171a..7cdb58d99 100644 --- a/tools/qfcc/test/structarray.r +++ b/tools/qfcc/test/structarray.r @@ -7,14 +7,17 @@ typedef struct { int ofs[]; } valstruct_t; +int foo[5] = {1, 2, 3, 4, 5}; valstruct_t *vs; int dst; int main () { + vs = (valstruct_t *)foo; for (int i = 0; i < 2; i++) { dst = vs.ofs[i]; } - return 1; + printf("dst = %d\n", dst); + return dst != 4; }