This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Dynamic array not initialized

Other Parts Discussed in Thread: TMS320DM6435

The following code seems to be producing a non-initialized array:

int num = 3;
int * vals = new int[num]();

If I understand it correctly, according to C++98 5.3.4.15 (expr.new) and 8.5.5 (dcl.init), it should be zero-initialized.

Upon further investigating, I found that if "num" is a const (or integer literal), it does indeed get zero-initialized.

Debug and release builds.

CGT v7.4.7

CCS v5.5.0.00077

TMS320DM6435

I am doing a COFF build, and I have read that COFF does not zero-initialize, but I think that is addressing a different case (static allocation).

For what it's worth (not much), gcc and Visual Studio did zero initialize.

Attached is an example project.

8468.Test_proj.zip

  • Thank you for reporting this problem.  I can reproduce it.  The code generated for ...

    user347219 said:
    int * vals = new int[num]();

    calls new, then it calls memset to initialize the memory to 0.  However, it passes a length of 0 to memset, which causes memset to do nothing.  I filed SDSCM00050960 in the SDOWP system to have this investigated.  Feel free to follow it with the SDOWP link below in my signature.

    A temporary workaround is to use release version 7.6.0.  I say temporary, because this release is "Intended for MCSDK, OpenMP, and/or OpenCL development" .

    Thanks and regards,

    -George