E2228
C++ Builder Programming Language
Severity: MinorWhat Does This Error Mean?
E2228 means the initializer list you provided has more values than the array, struct, or aggregate has members to receive them. For example, declaring an array of 3 ints but providing 5 initializer values produces E2228. The fix is to either reduce the number of initializers to match the size, or increase the declared size of the array.
Affected Models
- C++ Builder 10.x (Alexandria)
- C++ Builder 11 (Sydney)
- C++ Builder 12 (Athens)
- RAD Studio 11 and 12
Common Causes
- An array is declared with a fixed size smaller than the number of initializer values
- A struct initializer list provides values for members that do not exist
- Copy-paste error introduced extra values into an initializer list
- The array size was reduced during a refactor but the initializer list was not updated
How to Fix It
-
Count the values in the initializer list and compare with the declared size of the array or number of struct members. Adjust whichever is wrong.
If the initializer list is correct, increase the array size to match. If the array size is correct, remove the extra initializer values.
-
For arrays where the size should match the initializer, omit the size and let the compiler deduce it automatically. An array declared without a size takes its size from the initializer list.
Omitting the array size is the safest approach for fixed initializer lists — the compiler always keeps the size and list in sync. If you add or remove values from the initializer, the size updates automatically.
-
For struct initializers, check that the initializer list fields match the struct members in the correct order. Extra values in a struct initializer are also flagged by E2228.
C++ struct initializers assign values positionally — the first value goes to the first member, the second to the second, and so on. Extra values at the end have no member to initialize.
Frequently Asked Questions
Does E2228 also fire for too few initializers?
No — too few initializers is legal in C++. Any members or array elements not covered by the initializer list are zero-initialized. Only too many initializers is an error.