near/far function (#pragma near/#pragma far) [V1.05 or later]


This notifies the compiler of a function that is specified with __near/__far.

[Function]

-

A function specified with #pragma near is called as a function specified with __near.

Address reference of a function specified with #pragma near always returns a near pointer and the function is allocated to a section with the relocation attribute TEXT.

For details on __near, refer to "Specifying memory allocation area (__near /__far)".

-

A function specified with #pragma far is called as a function specified with __far.

Address reference of a function specified with #pragma far always returns a far pointer and the function is allocated to a section with the relocation attribute TEXT.

For details on __far, refer to "Specifying memory allocation area (__near /__far)".

-

A function specified with #pragma near ignores the keyword without a warning being output even for a function to which the __callt or __far keyword is added.

To use the function as a callt function, specify #pragma callt instead of #pragma near for the function.

-

A function specified with #pragma far ignores the keyword without a warning being output even for a function to which the __callt or __near keyword is added.

-

When #pragma callt, #pragma near, or #pragma far was specified together for the same function, the #pragma directives become valid in the priority order of #pragma callt > #pragma near > #pragma far.

[Usage]

-

Declare #pragma near/#pragma far before the first declaration of a variable.

#pragma near [(] function-name [,...][)]
#pragma far [(] function-name [,...][)]

[Restrictions]

-

If there are multiple declarations for the same variable and #pragma near/#pragma far is written at the location where the second or subsequent declaration takes effect, correct operation is not guaranteed. Declare #pragma near/#pragma far before the first declaration.

-

If a #pragma directive other than #pragma callt, #pragma near, or #pragma far is specified for the same function, a compilation error will occur.

-

If __inline is specified in the declaration of a target function of this #pragma directive, a compilation error will occur.

[Example]

#pragma near func1,func3
#pragma far  func2,func3         // #pragma near takes priority for func3.
 
extern void func1(void);         // Becomes __near without a warning due to 
                                 // the effect of #pragma near.
extern void __near func2(void);  // Becomes __far without a warning due to 
                                 // the effect of #pragma far.
extern void __callt func3(void); // Becomes __near without a warning due to 
                                 // the effect of #pragma near.
                                 // __callt becomes invalid without a warning.
 
void main(void)
{
    func1( );
    func2( );
    func3( );
      :
}

[Remark]

-

Difference between the __near/__far keyword and #pragma near/#pragma far

-

#pragma near/#pragma far can be specified for multiple functions at the same time.

-

The __far keyword cannot be used together with the __callt keyword or __near keyword, and a compilation error will occur if used so.

-

#pragma near/#pragma far invalidates the __callt/__near/__far keyword without a warning.