On 07.06.2013 12:29, JIA Pei wrote: > > To whom it may concern: > > I kept obtaining the following error message > *error 2: Initializer element is not constant* > while building the following code using *MCU8051IDE*, from Compiler > configuration, *MCU8051IDE *adopts *--std-sdcc89* . > > */1) Code A/* > */#include <reg51.h>/* > */sbit RELAY = P1^4;/* > */sbit K1 = P2^7;/* > */ > /* > */main() > /* > */{/* > */ if (!K1) RELAY = 0;/* > */ else RELAY = 1; /* > */}/* > > Clearly, *sdcc89* is not *keil C*, which is fantastic ! However, it > seems if I modify the above code and change it into > > */1) Code B/* > */#include <reg51.h>/* > > */main() > /* > */{/* > */sbit RELAY = P1^4;/* > */sbit K1 = P2^7;/* > */ if (!K1) RELAY = 0;/* > */ else RELAY = 1; /* > */}/* > > the above */code B/* can be successfully built. However, after I did > *hex->bin* and flash the *.bin* file into my board, the board doesn't > work at all. However, by building */code A/* and flashing the */.hex/* > file using *PZ-ISP* under Windows, the board works fine. > > > So, is there any suggestions by using sdcc? > */How can I make the code both built and work successfully by compiling > with sdcc?/*
Sorry, I cannot help you with your real problem, since I don't know much about the mcs51 target. But the error messages seem consistent with the C standard to me: Initializers for global variables need to be constant, while there is no such requirement for local variables (unless the local variables are static). Philipp ------------------------------------------------------------------------------ How ServiceNow helps IT people transform IT departments: 1. A cloud service to automate IT design, transition and operations 2. Dashboards that offer high-level views of enterprise services 3. A single system of record for all IT processes http://p.sf.net/sfu/servicenow-d2d-j _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user