This Technical Note discusses inconsistent use of a DATA pointer to point into CODE memory, (which the IAR AVR C/C++ compiler detects).
The below source code...
void fun (void)
{
;
}
void *p = (void*)fun;
int main( void )
{
return 0;
}
...will give this error message:
Error[Pe028]: expression must have a constant value ...\main.c
The message is produced because the pointer "void *" is a DATA pointer. This pointer type is very different from a FUNCTION pointer which points into CODE memory. The reported error occurs when the data pointer is smaller than the code pointer. Using the option -mt the default data pointer is 8 bits and with the -ms the default data pointer is 16 bits.
void fun (void)
{
;
}
typedef void (*f_p)(void);
f_p p = fun;
__nearfunc void fun (void)or use the pragma type_attribute:
{
;
}
void *p = (void*)fun;
#pragma type_attribute=__nearfunc
void fun (void)
{
;
}
void *p = (void*)fun;
All product names are trademarks or registered trademarks of their respective owners.
© IAR Systems 1995-2021 - All rights reserved.
We use cookies on this website to provide you with a better experience. You need to accept cookies to continue using this site. Cookies