'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.
Unified · Split
| @@ -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 */ |
| @@ -1752,6 +1752,8 @@ arrtype2 sinit22 = {5,6,7}; · 1751 unmodified lines | |||
| 1752 | int sinit23[2] = { "astring" ? sizeof("astring") : -1, | 1752 | int sinit23[2] = { "astring" ? sizeof("astring") : -1, |
| 1753 | &sinit23 ? 42 : -1 }; | 1753 | &sinit23 ? 42 : -1 }; |
| 1754 | 1754 | ||
| 1755 | extern int external_inited = 42; | ||
| 1756 | |||
| 1755 | void init_test(void) | 1757 | void init_test(void) |
| 1756 | { | 1758 | { |
| 1757 | int linit1 = 2; | 1759 | int linit1 = 2; |