AnsweredAssumed Answered

Problem started with CW10.4 (Kinetis)

Question asked by Mark Butcher on Nov 12, 2013
Latest reply on Nov 18, 2013 by Mark Butcher

Hi All

 

The following code started failing with CW10.4 and CW10.5 but was Ok with CW10.2:

 

static CHAR cTest[] = "abcdefghijklmnop";

..

while (i < 16) {

    if (cTest[i] == 'z') {

        cTest[i] = 'a';

    }

    else {

        cTest[i]++;

    }

    i++;

}

 

The code just shifts the string in the buffer each time it is called but the code itself is not the issue.

The problem is that cTEST[] is located in FLASH from CW10.4 (irrespective of optimisation settings) and so any attempt to modify the string content causes an exception.

 

No other compliers tested with (GCC, Keil, IAR) put the string in FLASH and CW10.2 put it in SRAM.

 

The code has been modified to allocate cTest[] on heap to avoid the problem but it would be interesting to know whether there is something specific controlling the behaviour and whether ANSI C defines specifically where the array should be located?

For example, if the code is changed to declare the array specifically as a const
static const CHAR cTest[] = "abcdefghijklmnop";

the compiler then throws an error on the lines where writes are made to it. This tells me that the compiler is treating the array (when not declared as const) as being modifiable but the linker is then locating it as a const.

I wonder whether there is some rule such as "make all strings consts" that is being followed??

 

Regards

 

Mark

Outcomes