This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IAR C51如何像keil C51一样, 将常量定位到code区?



程序里有很多字模,接近1kB,用了const.但发现还是占了XDATA

 5 898 bytes of CODE  memory
    18 bytes of DATA  memory (+ 31 absolute )
 4 016 bytes of XDATA memory
    64 bytes of IDATA memory
     8 bits  of BIT   memory

当改字模的大小时,CODE和XDATA的大小一起变。

有没有办法,像Keil C51一样,只占Code,不占XDATA?

  • 类型前面加const试试!

  • _code, _flash关键字试一试

  • IAR中const修饰的全局常量存放在非易失性ROM中(EEPROM或FLASH),const修饰的函数内局部常量存放在RAM区,const static修饰的局部静态常量存储在ROM区;IAR for 8051中使用const __code(两横)来指定存储在ROM区,但修饰局部变量必须与static同时使用,所以const与const __code功能相同。IAR for AVR中为__flash,并且都必须和const一起使用。KEIL中const与IAR中用法同,使用code关键字来定义分配到ROM中的常量,同样不可修改。code和__code都是特定编译器扩展的关键字,标准C中不存在。