Too many initializer errors for a simple array in bcc32

Matching the following example

struct S {}; int main() { S array[1] = { S() }; } 

with bcc32 I get the following error:

 [bcc32 Error] test.cpp(4): E2225 Too many initializers 

Is this a bug in bcc32 or am I missing something and the above example is invalid C ++?

Both Clang and GCC compile this example without any problems.

+4
c ++ compiler-errors borland-c ++
source share
1 answer

Borland BDS2006 (and possibly newer versions)

has some problems with the default constructor / destructor for class and struct inside its C ++ engine.

  • see bds 2006 C hidden memory manager conflicts for more information.

Adding a custom (even empty) constructor / destructor solves many problems, even yours. Try:

 struct S { S(){}; S(S& a){}; ~S(){}; S* operator = (const S *a){}; //S* operator = (const S &a){}; // use this only if you have dynamic allocation members }; int main() { S array[1] = { S() }; } 

I tried this in BDS2006 and it looks like it works (it's hard to say without anything inside a struct ), but you can compile and run at least ...

I first discovered this behavior in BDS2006 ... actually did not try BCB6 as it was confused from the very beginning and fired it after a few days (I think the worst BCB ever even exceeded BCB3,4 ) in BCB5 was everything ok (before BDS2006 was my favorite IDE) with this, so they should change the C ++ engine (do not confuse with runtime libs !!!).

Adds even an empty destructor constructor. If you get dynamic allocations, you need to handle rough ones. If you have a nested class / structure, be sure to also add them to them.

+3
source share

All Articles