Table of Contents        Previous topic       Next topic       

C/C++ COMPILER->Pragmas->#pragma data_seg

#pragma data_seg(["data-section-name","rdata-section-name"])

The data_seg pragma specifies the data section where the initialised C data objects are placed and the romable data section where the values are placed.  The section names can be any valid string contants.  To avoid conflict with the default sections used by the compiler, avoid using names beginning with a double underscore.

Using #pragma data_seg without any section-name strings resets allocation to the default sections.


#pragma data_seg("MY_INIT_DATA","MY_INIT_CODE")

int nItem1 = 54;
int nItem2 = 67;
int nItem3 = 98;

#pragma data_seg()

int nItem4 = 95;
int nItem5 = 96;
int nItem6 = 44;

The values 54, 67 and 98 will be placed in romable data section MY_INIT_CODE and space will be reserved for nItem1, nItem2 and nItem3 in section MY_INIT_DATA.

The values 95, 96 and 44 will be placed in the default romable data section and space will be reserved for nItem4, nItem5 and nItem6 in the default data section.

Only nItem4, nItem5 and nItem6 will be initialised to 95, 96 and 44 by the initialisation routine as supplied.  The following example shows how you might initialise the data in section MY_INIT_DATA:

* copy data in segment MY_DATA_VALUES (romable data) to MY_DATA_VARIABLES (data)

    section    MY_DATA_VALUES,romabledata
    section    MY_DATA_VARIABLES,data

    section    __CODE,code
    * init_my_cvars is called from outside of this module
    XDEF      _init_my_cvars
    move.l    #`size(MY_DATA_VALUES),d0
    * branch if MY_DATA_VALUES is empty
    beq.s    exit
    * initialise pointer to romable data section
    move.l    #MY_DATA_VALUES,a0
    * initialise pointer to data section
    move.l    #MY_DATA_VARIABLES,a1
    * copy from romable data section to data section
    move.b    (a0)+,(a1)+
    subq.l    #1,d0
    bne.s    moredata