3.7 __generic Keyword

The IAR __generic keyword is used with pointer definitions to allow those pointers to accesses objects from both data and program spaces, based on the MSb of the address. The pointer size varies with the selected device.

Suggested Replacement

There are MPLAB XC8 qualifiers that performs similar tasks to this keyword, but there are some differences in their effect.

If the const-in-program-memory feature is enabled (the default state), use the standard const qualifier provided by MPLAB XC8 with a pointer definition on devices which do not map their program memory in the data space to make that pointer 24-bits wide.

If this feature is disabled, using the -mno-const-data-in-progmem option, use both the const and __memx qualifiers with a pointer definition. In either case, the MSb of the pointer's address is used to determine whether to read from the data or program address spaces. Such pointers can access the lower 64 KB of the data space.

Caveats

If the const-in-program-memory feature is disabled, alternate versions of the string functions normally provided by <string.h> must be used to access string objects located in program memory.

Examples

Consider migrating IAR code such as:
const __generic char * p;
volatile char x;
int main(void) {
    x = *p;
}
to MPLAB XC8 code similar to:
#include <xc.h>
 
const __memx char * p;
volatile char x;
int main(void) {
    x = *p;
}

Further Information

See the Special Type Qualifiers and Options Specific to AVR Devices sections in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on this qualifier and option.