Monday, 23 February 2015

embedded - Variable declaration with @ in C


I am reading some C code and came across this declaration in the program:


unsigned char serv_ctr @0x0002;

Can someone point me to documentation, or explain what the "@0x0002" is for in the Mplab XC8 v1.35 C compiler?



Answer



This is to specify an absolute address to place the variable at.
From the XC8 compiler manual page 27, section 2.5.2 Absolute Addressing:



Variables and functions can be placed at an absolute address by using the __at() construct

......
2.5.2.2 DIFFERENCES
The 8-bit compilers have used an @ symbol to specify an absolute address



No comments:

Post a Comment