History

Accept extern initialized file-scope variables

'extern int i = 42;' at file scope (but not in function scope!) is allowed and is a proper definition, even though questionable style; some compilers warn about this.

Michael Matz committed 9 years ago

Commit 94ac9f21 parent 5732a182 files · +4 −1Browse files

Unified · Split

2 files
  1. tccgen.c +2 −1
  2. tests/tcctest.c +2 −0
tccgen.c+2−1
@@ -6955,7 +6955,8 @@ found: · 6954 unmodified lines
69556955 has_init = (tok == '=');
69566956 if (has_init && (type.t & VT_VLA))
69576957 tcc_error("variable length array cannot be initialized");
6958− if ((type.t & VT_EXTERN) || ((type.t & VT_BTYPE) == VT_FUNC) ||
6958+ if (((type.t & VT_EXTERN) && (!has_init || l != VT_CONST)) ||
6959+ ((type.t & VT_BTYPE) == VT_FUNC) ||
69596960 ((type.t & VT_ARRAY) && (type.t & VT_STATIC) &&
69606961 !has_init && l == VT_CONST && type.ref->c < 0)) {
69616962 /* external variable or function */
tests/tcctest.c+2−0
@@ -1752,6 +1752,8 @@ arrtype2 sinit22 = {5,6,7}; · 1751 unmodified lines
17521752 int sinit23[2] = { "astring" ? sizeof("astring") : -1,
17531753 &sinit23 ? 42 : -1 };
17541754
1755+extern int external_inited = 42;
1756+
17551757 void init_test(void)
17561758 {
17571759 int linit1 = 2;