Compiler directive error

Discussion in 'Programmer's Corner' started by dpeterson3, Jun 7, 2010.

  1. dpeterson3

    Thread Starter New Member

    Oct 9, 2009
    19
    0
    I haven't used compiler directives too much in the past, but I found somewhere where one would be useful if I could get it to compile. I am writing a software PWM class for an AVR and have a function called generate_PWM

    Code ( (Unknown Language)):
    1.  
    2. #define Generate_PWM (c) { \
    3.     if (c < 6) pinlevelB &= ~(1 << PORTB##c); \
    4.     else { \
    5.         c = c - 6; \
    6.         pinlevelB &= ~(1 << PORTC##c);  \
    7.     }
    8.  
    It gets called from here
    Code ( (Unknown Language)):
    1.  
    2. int i = 0;
    3.     for (i = NUMPWM; i = 0; i++) {
    4.         if (pwm[i] == timer) {
    5.             Generate_PWM(i);
    6.         }
    7.         else if (timer == 0) {    
    8.             Generate_PWM(i);
    9.         }
    10.     }
    11. }
    12. [/i]

    I get this error message when I try to compile
    Code ( (Unknown Language)):
    1.  
    2. softPWM.c:36: error: ‘c’ undeclared (first use in this function)
    3. softPWM.c:36: error: (Each undeclared identifier is reported only once
    4. softPWM.c:36: error: for each function it appears in.)
    5. softPWM.c:36: error: expected ‘;’ before ‘{’ token
    6. softPWM.c:42: error: expected declaration or statement at end of input
    7. softPWM.c:42: error: expected declaration or statement at end of input
    8.  
    I have seen this done before for PIC programing (in fact, I am almost borrowing this directly). Not sure why it won't compile. Thanks in advance
     
  2. BenjaminSweet

    New Member

    Jun 4, 2010
    8
    7
    Remember that with pre-processor macros, the pre-processor will replace the identifier string with replacement string.

    Look closely at the macro code that you posted. Where does the identifier string end and the replacement string begin?

    Good luck!
     
    Last edited: Jun 8, 2010
Loading...