This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

error C141 and error C202

Hello,
when trying to compile an small C program with uVision3 v3.53 I'm coming across some unexpected - at least to me - compilation errors, following is the complete program:

#include <reg515c.h>
#define H 1 /* H abk. von HIGH */
#define L 0 /* L abk. von LOW */

sbit P4_0 = P4^0;

main()
{
        P4 = 0xFF;      /* Port 4 als Eingang eingerichtet */

        /*Why on earth these lines cannot be compiled?*/
        
        unsigned char zustand = H;
        unsigned int i;
        
        while(1)
        {

                for(i = 0; i <= 8; i++)
                {
                        while(P4_0 == H)
                                ;
                        if(P4_0 == L && zustand == H)
                        {
                                zustand = L;
                                P1 = i;
                        }
                        while(P4_0 == L)
                                ;
                        if(P4_0 == H && zustand == L)
                        {
                                zustand = H;
                        }
                }
        }
}

And the error the compiler reports are:

Build target 'mM-515'
assembling STARTUP.A51...
compiling PinNummern.c...
PINNUMMERN.C(11): error C141: syntax error near 'unsigned'
PINNUMMERN.C(11): error C202: 'zustand': undefined identifier
PINNUMMERN.C(12): error C141: syntax error near 'unsigned'
PINNUMMERN.C(12): error C202: 'i': undefined identifier
PINNUMMERN.C(13): error C202: 'zustand': undefined identifier
PINNUMMERN.C(18): error C202: 'i': undefined identifier
PINNUMMERN.C(22): error C202: 'zustand': undefined identifier
PINNUMMERN.C(24): error C202: 'zustand': undefined identifier
PINNUMMERN.C(25): error C202: 'i': undefined identifier
PINNUMMERN.C(29): error C202: 'zustand': undefined identifier
PINNUMMERN.C(31): error C202: 'zustand': undefined identifier
Target not created

The offending lines are the ones in red, neither the variable zustand nor i have sfr or sbit type so it should be allowed to declare them inside a function.
When taking those variables out of main's body this way:

#include <reg515c.h>
#define H 1 /* H abk. von HIGH */
#define L 0 /* L abk. von LOW */

sbit P4_0 = P4^0;

unsigned char zustand = H;
unsigned int i;

main()
{
        P4 = 0xFF;      /* Port 4 als Eingang eingerichtet */

        /* etc */

The program compiles without errors.

Any help would be appreciated. Thanks.

Parents
  • "That's a recipe for headaches."

    Agreed!

    But, even with better names, is there really any point in defining "HIGH" as 1 ?

    Isn't that (nearly) as bad as:

    #define ZERO 0
    #define ONE  1
    

    A more useful definition would be to give names that actually describe what the High and Low mean; eg,

    #define LED_OFF 1 /* Writing a 1 (high) turns the LED off */
    #define LED_ON  0 /* Writing a 0 (low)  turns the LED on  */
    

    Then, if you change the "sense" of the drive, you only need to change the definitions - the usage of LED_ON and LED_OFF remain constant!

    :-)

Reply
  • "That's a recipe for headaches."

    Agreed!

    But, even with better names, is there really any point in defining "HIGH" as 1 ?

    Isn't that (nearly) as bad as:

    #define ZERO 0
    #define ONE  1
    

    A more useful definition would be to give names that actually describe what the High and Low mean; eg,

    #define LED_OFF 1 /* Writing a 1 (high) turns the LED off */
    #define LED_ON  0 /* Writing a 0 (low)  turns the LED on  */
    

    Then, if you change the "sense" of the drive, you only need to change the definitions - the usage of LED_ON and LED_OFF remain constant!

    :-)

Children