Search code examples
c8051

syntax error, expecting declaration seen while compiling C code for 8051 microcontroller


I have a piece of C code in a header file used for a 8051 microcontroller as below -

#define Sfr(x, y)       sfr x = y
#define Sbit(x, y, z)   sbit x = y^z
#define Sfr16(x,y)      sfr16 x = y

/*----------------------------------------*/
/* Include file for 8051 SFR Definitions  */
/*----------------------------------------*/

/*  BYTE Register  */

Sfr(P0 , 0x80);      
Sbit (P0_7 , 0x80, 7);
Sbit (P0_6 , 0x80, 6);

When compiling, I get the error line 17: syntax error, expecting declaration. Any mistake in the usage of the macro?


Solution

  • Each time you use any of your macros, it declares the same variable 'x' over and over.

    There's also no evidence that the compiler knows what sfir or sbit orsfr16 are.