Why do I get these errors?

Help
AP2k
2007-05-22
2013-03-12
  • AP2k
    AP2k
    2007-05-22

    I'm trying to compile this basic program using "sdcc -c delays.c"
    =============================#include "delays.h"

    void DELAY_10micro( unsigned char  factor){
    __critical{
            for(unsigned char i=0; i<factor; i++){
                    for(unsigned char k=0; k<(unsigned char) 10*OSC_FAC; k++){}
            }
        }
    }

    void DELAY_1milli(unsigned char factor){
            __critical{
            for(unsigned char i=0; i<factor; i++){
                    for(unsigned char k=0; k<(unsigned char) 1000*OSC_FAC; k++){}
            }
       }
    }

    //Both sets of the above routines are to be protected from interrupts

    void DELAY_100milli(unsigned char factor){
            for(unsigned char i=0; i<factor; i++){
                    delay_milli(100);
            }
    }

    void DELAY_1second(unsigned char factor){
            for(unsigned char  i=0; i<factor; i++){
                    delay_100milli(10);
            }
    }
    ===================================
    ===================================

    And I get the following errors:

    ===================================
    delays.c:6: syntax error: token -> 'unsigned' ; column 20
    delays.c:6: syntax error: token -> ')' ; column 45
    delays.c:7: syntax error: token -> ')' ; column 84
    delays.c:15: syntax error: token -> ')' ; column 45
    delays.c:16: syntax error: token -> ')' ; column 86
    delays.c:25: syntax error: token -> ')' ; column 45
    delays.c:6: error 20: Undefined identifier 'i'
    delays.c:7: error 20: Undefined identifier 'k'
    delays.c:15: error 20: Undefined identifier 'i'
    delays.c:16: error 20: Undefined identifier 'k'
    delays.c:25: error 20: Undefined identifier 'i'
    delays.c:25: error 103: code not generated for 'DELAY_10micro' due to previous errors
    delays.c:31: syntax error: token -> 'unsigned' ; column 20
    delays.c:31: syntax error: token -> ')' ; column 45
    delays.c:31: error 20: Undefined identifier 'i'
    delays.c:31: error 103: code not generated for 'DELAY_1second' due to previous errors

     
    • Maarten Brock
      Maarten Brock
      2007-05-27

      for(unsigned char i=0; i<factor; i++){

      Allthough declaring 'i' inside the for construct is allowed in C99 (it's not in C89) it's not supported by SDCC. You must declare it the beginning of the surrounding block/function.