This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

const placed in DATA segment

Hi All,
when I write:
const char mysting[] ={"my string"};

data are placed to DATA segment, not code sement. I know if it would be written like this:

code char mysting[] ={"my string"};

data will be placed in code segment. What I have to do for automatic placing const data to code segment? I did it by #define const code
But may be other ways are exist.

Thanks,
Vladimir

Parents
  • 'const' is similar read-only, but it is not a memory_storage_qualifier.

    Look at the example:

    struct CCC {
      const int x;
      int y;
    } ccc = { 1, 2 };
    
    void func(const char *str)
    { char * ptr;
    
      ptr = str;  // MUST produce WARNING
    
      *ptr = 'B'; // LEGAL
      *str = 'A'; // ILLEGAL
    
      ccc.y = 5;  // LEGAL
      ccc.x = 2;  // ILLEGAL
    }
    


    In example above, how possible solid object like 'struct' divide to different memory classes ?

    'x' member to 'code' memory but
    'y' member to 'data/xdata' memory ?

    Obviously, this is absurd.

    How work IAR in this case ?

Reply
  • 'const' is similar read-only, but it is not a memory_storage_qualifier.

    Look at the example:

    struct CCC {
      const int x;
      int y;
    } ccc = { 1, 2 };
    
    void func(const char *str)
    { char * ptr;
    
      ptr = str;  // MUST produce WARNING
    
      *ptr = 'B'; // LEGAL
      *str = 'A'; // ILLEGAL
    
      ccc.y = 5;  // LEGAL
      ccc.x = 2;  // ILLEGAL
    }
    


    In example above, how possible solid object like 'struct' divide to different memory classes ?

    'x' member to 'code' memory but
    'y' member to 'data/xdata' memory ?

    Obviously, this is absurd.

    How work IAR in this case ?

Children