To change the allocated section, specify the attribute strings using #pragma section directive.
#pragma section gp_disp16 "mysdata" int a = 1; /*allocated to mysdata.sdata attribute section*/ int b; /*allocated to mysdata.sbss attribute section*/ #pragma section default |
See "4.2.4.1 Allocation of function and data to section" for details about how to use the #pragma section directive.
When referencing a variable using the #pragma section directive from a function in another source file, it is necessary to declare the affected variable with the extern specifier and the same #pragma section directive in the file that performs reference.
Unlike when specifying a variable by means of a definition or declaration, it outputs the following error if the variable cannot be accessed with the specified section attribute.
#pragma section zconst const unsigned char table_data[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; /*allocated to .zconst section*/ #pragma section default |
#pragma section zconst extern const unsigned char table_data[]; /*allocated to .zconst section*/ #pragma section default |
Code such as the following can be used if portability of C source to the SH family of compilers is a concern.