Skip to main content
Knowledgebase
Home
Renesas Singapore - Knowledgebase

How to write source code such as variables and const variables?

Latest Updated:09/04/2015

Question:

Is there any efficient way to write source code such that variables and const variables are assigned to specific sections while they are mixed in the source code?

Answer:

Since the #pragma section directive does not distinguish between variables and const constants, the last #pragma section directive will be valid.  
That is, for the code below, although val1 and val3 will be placed in the user.sdata23 and user.sbss23 sections, respectively, the directive “#pragma section zconst23 “user”” becomes invalid for val2, so it will be placed in the default .const section.

 
  ------------------------------

  #pragma section zconst23 "user"

  #pragma section gp_disp23 "user"

  int val1=1;

  const int val2=1;

  int val3;

  ------------------------------
  

When declarations or definitions of variables and const variables are mixed, you do not have to change the order if you use the “#pragma section [character string]” designation and –Xsection option in combination.
If you specify the -Xsection=data=gp_disp23 and -Xsection=const=zconst23 compiler options, val1, val3, and val2 will be placed in the user.sdata23, user.sbss23, and user.zconst23 sections, respectively.

  ------------------------------

  #pragma section user

  int val1=1;

  const int val2=1;

  int val3;

  const int val4=1;

  ------------------------------ 
Suitable Products
C Compiler Package for RH850 Family