AnsweredAssumed Answered

C++ Constants going to SRAM

Question asked by Manish Sangram on Oct 5, 2017
Latest reply on Oct 17, 2017 by ZhangJennie

Hi,

 

We are using S12ZVMC128 and using Codewarior 10.6

 

We were running out of SRAM and when looking into the matter by referring to the MAP file we realized that even though we have marked constants as static and const, these are being treated as variables and are being put in SRAM.  This should not be the case because obviously a constant is a constant and should only reside in RO memory.

 

Example of how we have defined a constant is given below

 

CClassX.h

class X{

static const unsigned char ConstantVal;

};

 

CClassX.cpp

const unsigned char X::ConstantVal = 100;

 

Why is the compiler creating variables in SRAM for such constants? 

How can we turn them off.

 

We checked that similar static constants outside class definition (module level) are correctly put only in RO so it cannot be any form of speed optimization.

Original Attachment has been moved to: Demo.zip

Outcomes