User type constants not correctly allocated when compiled in "Release"


C++ Builder XE8 subscription update 1 Professional - running on Win 7 (32 bit) PC.

I have a fairly large VCL project (on going). Latest version compiles, links without errors or warnings when compiling in "debug" mode and runs as expected. When I change to "release" mode the code still compiles and links without any errors or warnings but it does not run correctly: some const arrays of user types seem to be allocated memory but they are not correctly initialised. The software runs as if all the integers in the user types are initialised as zero and all the Strings (aka VCL Unicode strings) are initialised as empty strings. Individual const types of the user type ARE initialised correctly, it is only the const arrays of the individual const types that are not.

The problem is consistent - ie if I change settings back to "debug" and recompile then the application works as expected. If I change back to "release" it fails again.

I am not quite sure how to debug this further (any constructive ideas welcome!).

Has anyone else seen this?

Responses (3)
  • Accepted Answer

    Tuesday, August 23 2016, 08:17 AM - #Permalink

    I have just run across the same problem (now using the "Classic" win 32 C++ compiler in Seattle 10.1 - subscription update 1). Has anyone else had any problems with the initialisation of a constant array using the copy constructor as above?

    The reply is currently minimized Show
  • Accepted Answer

    Thursday, January 14 2016, 03:03 AM - #Permalink

    OK - now know what is the cause of the problem: It is the "optimisation options". In debug mode this defaults to "disable all optimisations". In release mode we had the optimisation set to "generate fastest code". If we set the release mode options to "disable all optimisations" the compiled code works as it should. We have confirmed that the "fastest code" setting does correctly allocate memory for the const array, it just doesn't initialise it correctly. With our code this means that it does not crash, but it does not work correctly.

    We regard this as a bug (and it seems to also exist in C++ Seattle 10 subscription upgrade 1) in that we feel the coder is entitled to interpret "generate fastest code" as actually meaning "generate fastest code that still runs ok".

    Note: we have not tried this with the Win 32 CLANG compiler in C++ Seattle 10.

    Question for embarcadero staff: Will someone formally add this to the bugs list or do we need to generate a formal notification?

    The reply is currently minimized Show
  • Accepted Answer

    Wednesday, January 13 2016, 08:13 AM - #Permalink

    Today I have tried compiling/linking on C++ Seattle 10 Subscription upgrade 1 running on a Win 7 64 bit machine but targeting Win 32. Exactly the same problem: compile in "debug" all code works ok. compile in "release" and user type constants are not correctly initialised. The user type and it's failure in release mode are as follows (in a C++ header file)

    class TSpecialType {
       int Number;
       String Text;
       String Text2;
       /* various functions removed here */
       bool operator==(TSpecialType rhs);
       bool operator!=(TSpecialType rhs);
       TSpecialType &operator=(TSpecialType rhs);
       TSpecialType(const TSpecialType &ToCopy);
       TSpecialType(int Number, String Text,
              String Text2= String(""));

    extern const TSpecialType SFSOK;  // *** these two are initialised correctly at all times ***
    extern const TSpecialType SFSOpenCircuit;

    /* also elsewhere in a C++ *.cpp file I have and want to use the following array */

    const TSpecialType ArrayOfTSpecialType[2] =
       SFSOK,   // !!! these two are initialised with zero and empty strings when I compile in "release" mode
       SFSOpenCircuit  // !!! but they are initialised correctly when I compile in "debug" mode




    The reply is currently minimized Show
Your Reply

Please login to post a reply.........