添加到 mizo 的答案(我无法发表评论,因为我主要回答 Arduino.SE 和 EE.SE)
XC8 编译器还具有在运行时确定适当地址空间的功能。
所以是的,Hi-Tech PICC-18 做到了这一点,但并不是唯一这样做的编译器。
尽管我可以理解目前是否不可能切换编译器。
因此,您可能希望在string.h
/** @name memcpypgm2ram
* The {\bf memcpypgm2ram} function performs a {\bf memcpy} where
* {\bf s1} points to data memory and {\bf s2} points to program
* memory.
* @param s1 pointer to destination in data memory
* @param s2 pointer to source in program memory
* @param n number of characters to copy
*/
void *memcpypgm2ram (auto void *s1, auto const MEM_MODEL rom void *s2, auto sizeram_t n);
/** @name memcpyram2pgm
* The {\bf memcpyram2pgm} function performs a {\bf memcpy} where {\bf s1}
* points to program memory and {\bf s2} point to data memory.
* @param s1 pointer to destination in program memory
* @param s2 pointer to source in data memory
* @param n number of characters to copy
*/
MEM_MODEL rom void *memcpyram2pgm (auto MEM_MODEL rom void *s1, auto const void *s2, auto sizeram_t n);
你可以让你的功能像:
void YourStringFunction(ramstring);
void YourStringFunctionAccpetingRom(romstring){
YourStringFunction(memcpypgm2ram(romstring));
}
^这不是实际代码,更多的是伪代码。另外,我不确定它是否有效。