>- should be a near call. If I called the same function from code in a different page it would force the
>compiler to generate CALL and RTC, correct?
No.
The compiler only considers which qualifiers a function was declared/defined with and in which section the function is placed.
The compiler has no glue about actual addresses, therefore he cannot generate different code whether two functions end up in the same page or not.
>I noticed that the bean code uses CODE_SEG pragmas, do I need to do that as well?
Depends on your code I would think....
In the banked memory model, interrupt handlers must be allocated non banked. Other than that, there is little need for a
#pragma CODE_SEG in plain C code.
It is important that function declarations (in header files) and the function definition are defined in the same segment.
E.g. Typical setup of a function in a non default segment looks like this:
/* File.h */#ifndef FILE_H_#define FILE_H_#pragma push#pragma CODE_SEG /* qualifiers, if any. */ MY_FILE_SEGvoid fileFunc1(void);void fileFunc2(void);#pragma pop#endif /* FILE_H_ */
/* File1.c */#include "file.h" /* include important for compiler warnings! */#pragma CODE_SEG /* qualifiers, if any. (same as in file.h!) */ MY_FILE_SEGvoid fileFunc1(void){ /* Whatever */}void fileFunc2(void){ /* Whatever */}
Note:
- The pragma must be present for the declaration also.
- Using __far/__near qualifiers is only necessary (I would say reasonable) in few cases,
and only when code gets placed in user defined sections.
Daniel