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
6955 has_init = (tok == '=');6955 has_init = (tok == '=');
6956 if (has_init && (type.t & VT_VLA))6956 if (has_init && (type.t & VT_VLA))
6957 tcc_error("variable length array cannot be initialized");6957 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) ||
6959 ((type.t & VT_ARRAY) && (type.t & VT_STATIC) &&6960 ((type.t & VT_ARRAY) && (type.t & VT_STATIC) &&
6960 !has_init && l == VT_CONST && type.ref->c < 0)) {6961 !has_init && l == VT_CONST && type.ref->c < 0)) {
6961 /* external variable or function */6962 /* external variable or function */
tests/tcctest.c+2−0
@@ -1752,6 +1752,8 @@ arrtype2 sinit22 = {5,6,7}; · 1751 unmodified lines
1752int sinit23[2] = { "astring" ? sizeof("astring") : -1,1752int sinit23[2] = { "astring" ? sizeof("astring") : -1,
1753 &sinit23 ? 42 : -1 };1753 &sinit23 ? 42 : -1 };
1754 1754
1755extern int external_inited = 42;
1756
1755void init_test(void)1757void init_test(void)
1756{1758{
1757 int linit1 = 2;1759 int linit1 = 2;