Microchip Technology SW006023-2N Data Sheet

Page of 238
Functions
 2012 Microchip Technology Inc.
DS51686E-page 127
used
Indicate to the compiler that the function is always used and code must be generated 
for the function even if the compiler cannot see a reference to the function. For 
example, if inline assembly is the only reference to a static function.
vector
Generate a branch instruction at the indicated exception vector which targets the 
function. See Chapter 11. “Interrupts” anSection 11.5 “Exception Handlers”.
warn_unused_result
A warning will be issued if the return value of the indicated function is unused by a 
caller.
weak
A weak symbol indicates that if another version of the same symbol is available, that 
version should be used instead. For example, this is useful when a library function is 
implemented such that it can be overridden by a user written function.
10.3
ALLOCATION OF FUNCTION CODE
Code associated with C/C++ functions is normally always placed in the program Flash 
memory of the target device.
Functions may be located in and executed from RAM rather than Flash by using the 
__ramfunc__
 and __longramfunc__ macros.
Functions specified as a RAM function will be copied to RAM by the start-up code and 
all calls to those functions will reference the RAM location. Functions located in RAM 
will be in a different 512MB memory segment than functions located in program 
memory, so the longcall attribute should be applied to any RAM function, which will 
be called from a function not in RAM. The __longramfunc__ macro will apply the 
longcall
 attribute as well as place the function in RAM
1
.
#include <sys/attribs.h>
/* function ‘foo’ will be placed in RAM */
void __ramfunc__ foo (void)
{
}
/* function ‘bar’ will be placed in RAM and will be invoked
   using the full 32 bit address */
void __longramfunc__ bar (void)
{
}
10.4
CHANGING THE DEFAULT FUNCTION ALLOCATION
The assembly code associated with a C/C++ function can be placed at an absolute 
address. This can be accomplished by using the address attribute and specifying the 
virtual address of the function, see Section 6.12 “Variable Attributes”.
Functions can also be placed at specific positions by placing them in a user-defined 
section and then linking this section at an appropriate address, see 
Section 6.12 “Variable Attributes”.
1. Specifying 
__longramfunc__
 is functionally equivalent to specifying both 
__ramfunc__
 and
__longcall__
.