Tell me more ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

Been trying to get this to compile but keep getting the following error:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stdlib.h:111: error: expected unqualified-id before 'int'

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stdlib.h:111: error: expected `)' before 'int'

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/include/stdlib.h:111: error: expected `)' before 'int'



    // Receiver Code

#include <ServoTimer2.h>

ServoTimer2 servosteer;  // create servo object to control a servo 
ServoTimer2 servospeed;  // create servo object to control a servo 
//MEGA pin 23 receive pin - displays characters sent by RF

#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round
void setup()
{
  servosteer.attach(3);  // attaches the servo on pin 25 to the servo object 
  servospeed.attach(4);  // attaches the servo on pin 27 to the servo object 
  // lcd.init();
  Serial.begin(9600);   // Debugging only
  Serial.println("setup");

  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for DR3100
  vw_setup(4000);    // Bits per sec
  vw_set_rx_pin(8);
  vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen)) // Non-blocking
  {
    //invalid message length must be S/B/F/L/R + number (max 3 digits)
    if (buflen < 3 || buflen > 5)
      return;
    digitalWrite(13, true); // Flash a light to show transmitting

    char val[buflen]; //Same as buf, last char will be used for null terminator
    memset(val, '\0', sizeof(val));

    //Copy value from string i.e. 213 from R213 into separate string
    strncpy(val, (char *)buf + 1, buflen - 1);

    //convert string containing value to integer e.g. "213" to 213.
    int VAL = atoi ( val );

    switch (buf[0]) {
    case 'X': //Deadmans finger stop all
      Serial.print("Deadmans finger");
      servospeed.write(1500);

      break;
    case 'P':
      Serial.print("Pitch ");
      Serial.println(VAL);
      servospeed.write(544+VAL*10);

      break;
    case 'R':
      Serial.print("Roll ");
      Serial.println(VAL);
      servosteer.write(544+VAL*10);

      break;
    default:
      break;
    }
  }
  digitalWrite(13, false); // Flash a light to show transmitting
}
share|improve this question
In Arduinos, do you have to specify the product number in a pound define or is that a setting in the software? – Kellenjb Jul 3 '10 at 12:42
is this code an exact paste from your arduino editor? – JustJeff Jul 3 '10 at 14:37
@Kellenjb: the Arduino IDE has a menu setting (Tools;Board) for that, which doesn't seem to insert anything into the edit window. – JustJeff Jul 3 '10 at 15:24

2 Answers

If you look carefully at the error messages, the compiler is complaining about line 111 in the stdlib.h file. Since you didn't explicitly #include <stdlib.h>, it seems likely that the compiler is implicitly including it at some point after all those unusual #undef statements.

If you have to keep the #undefs, you could try putting an explicit #include <stdlib.h> at the very top of the file.

share|improve this answer

This whole block looks suspect.

#undef int
#undef abs
#undef double
#undef float
#undef round

What error messages do you get if you remove that?

share|improve this answer
This is a perfectly good attempt at an answer, but I do not understand why it was accepted as the correct answer if it did not fix his problem. – Kellenjb Jul 3 '10 at 12:43
I agree, please remove the "correct answer" tick until someone solves your problems. – Toby Jaffey Jul 3 '10 at 12:45
As a note to Alex, If you accept someones answer, you are telling everyone that your question has been answered and that you don't really need any more responses. – Kellenjb Jul 3 '10 at 12:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.