From f814f95ca5f996defa14590b7346c76a65418e7e Mon Sep 17 00:00:00 2001 From: Ali Gholami Rudi Date: Thu, 1 Sep 2011 23:08:20 +0430 Subject: [PATCH] ncc: better char array initialization The patch handles: char s[] = {"sth"}; char s[][3] = {"a1", "a2"}; --- ncc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ncc.c b/ncc.c index 8b9fe42..ca65dc5 100644 --- a/ncc.c +++ b/ncc.c @@ -1281,6 +1281,12 @@ static void initexpr(struct type *t, int off, void *obj, } else if (t->flags & T_ARRAY) { struct type *t_de = &arrays[t->id].type; int i; + /* handling extra braces as in: char s[] = {"sth"} */ + if (TYPE_SZ(t_de) == 1 && tok_see() == TOK_STR) { + set(obj, off, t); + tok_expect('}'); + return; + } for (i = 0; tok_see() != '}'; i++) { long idx = i; struct type *it = t_de; @@ -1291,7 +1297,8 @@ static void initexpr(struct type *t, int off, void *obj, tok_expect(']'); tok_expect('='); } - if (tok_see() != '{') + if (tok_see() != '{' && (tok_see() != TOK_STR || + !(it->flags & T_ARRAY))) it = innertype(t_de); initexpr(it, off + type_totsz(it) * idx, obj, set); if (tok_jmp(',')) -- 2.11.4.GIT