AnsweredAssumed Answered

Why const is not const?

Question asked by Teckna Teckna on Nov 28, 2012
Latest reply on Nov 29, 2012 by Teckna Teckna

Hi everyone,

 

I'm working with CW 10.2 and Kinetis MK60DN512.

 

I created a bareboard project with a single test file:

 

#include <stdio.h>

#include "derivative.h" /* include peripheral declarations */

 

typedef struct
{
     const char *str;
} TEST;

 

const TEST Test0 =
{
     "STRING0"
};
const TEST Test1 =
{
     "STRING1"
};

const TEST *Test[ 2 ] =
{
     &Test0,
     &Test1
};

 

int main( void )
{
     int i;

 

     for( i = 0; i < 2; i++ )
          printf( Test[ i ]->str );

     while( 1 )
     {
          i++;

     }

 

     return( 0 );
}

 

In the map file the two const structs Test0 and Test1 are located in .rodata section (flash), but the const struct Test is located in the .app_data section (ram) even if it's declared as const.

Why is there such difference? I expected all the structs to be located in the .rodata section.

 

Many thanks

Teckna

Outcomes