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.

CCS/MSP430G2553: C Structure storing

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hello,

I have made two structure in my project first structure member will constant but the variable not define constant and second structure member and variable both define constant so what will exactly difference both structure memory point of view?

My first and second structure where is it store in memory like (RAM or FLASH pls be specified this) 

In my both structure which one structure is constant? 

1. 

#define mac 2


struct student{

const unsigned int max;
const unsigned int min;

}stu[mac]={
               {.max=10,.min=20},
               {.max=30,.min=40}
            };

2.


struct student{

const unsigned int max;
const unsigned int min;

}const stu[mac]={
                        {.max=10,.min=20},
                        {.max=30,.min=40}
                    };

  • Hey Yash,

    Interesting question and I fully know the answer.  I decided to do some really quick testing, and both seem to have the same results. 

    They both store the data in the .const data section which is specified in your linker file.  You can see this when you build the project by looking at the .map file in your debug folder. 

    You can also debug the project on your device and use the memory and expression viewer to see where these variables are being stored and what the pointers read. 

    Hope this helps!

    JD  

  • Hey,

    My question like this

    Below are 2 structures. In the first one,stu[] is allocated to SRAM in the map file. Shouldn't this be in the flash?

    In the 2nd case, stu[] is allocated to flash in the map file.

    Our problem is that the structure is meant to have both const and unsigned int(for SRAM).But if initialized as const as in the 2nd case this is not possible. How to do this ie add a struct member for SRAM as in case 3.

    And which one structure store on FLAH and which structure store in RAM?

    case 1.

    Struct para{

    const unsigned int max;

    const unsigned int min;

    struct group{

    const unsigned int scale;

    const unsigned int dc;

    }uni;

    }stu[2]={

               {.min=10,.min=2,{.scale=5,.dc=20}},

               {.min=30,.min=2,{.scale=5,.dc=40}}

    };

    case 2.

    Struct para{

    const unsigned int max;

    const unsigned int min;

    struct group{

    const unsigned int scale;

    const unsigned int dc;

    }uni;

    }const stu[2]={

           {.min=10,.min=2,{.scale=5,.dc=20}},

           {.min=30,.min=2,{.scale=5,.dc=40}}

    };

    case 3

    struct para{

    const unsigned int max;

    const unsigned int min;

    unsigned int volt;

    struct group{

    const unsigned int scale;

    const unsigned int dc;

    }uni;

    }const stu[2]={

         {.min=10,.min=2,{.scale=5,.dc=20}},

         {.min=30,.min=2,{.scale=5,.dc=40}}

    };

    Regards

    Yash Shah

**Attention** This is a public forum