Using #pragma section <sectname> begin/end

As an alternative to the above method, you could use #pragma section <sectname> begin/end syntax if the function is defined in the same file as the #pragma define_section.

Listing: Example of using #pragma section<sectname> begin/end

#pragma section FARSECT begin

int farfunc(int i)

{

    return i++;

}

#pragma section FARSECT end

int main()

{

    int j=0;

    j = farfunc(j);

}

If the far function is defined in another module (an extern function), the #pragma define_section and __declspec or #pragma section must also be specified in the module containing the function definitions and must be identical to the #pragma define_section, __declspec, or #pragma section that references the far function.

Listing: Example of using#pragma define_section and __declspec

====== main.c  ======

#pragma define_section FARSECT ".farsect" far_abs RX

__declspec(section "FARSECT") extern void farfunc(int);

int main()

{

    farfunc(3);

}

======= file1.c =======

#pragma define_section FARSECT ".farsect" far_abs RX

__declspec(section "FARSECT") extern void farfunc(int);

void farfunc(int j)

{

    return;

}
Note: The linker control file must place the ELF section ".farsect" appropriately. A far_abs section does not imply any restrictions on placement in the memory map.