Something is wrong with setup() and loop()

So I keep getting these errors, and I cannot understand why… :frowning:
It seems that the code has errors only in core stuff like OUTPUT, HIGH, and digitalWrite

Errors:

Arduino_RFID_Sensor_Fun.cpp: In function 'void setup()':
Arduino_RFID_Sensor_Fun:12: error: 'Serial' was not declared in this scope
Arduino_RFID_Sensor_Fun:13: error: 'OUTPUT' was not declared in this scope
Arduino_RFID_Sensor_Fun:13: error: 'pinMode' was not declared in this scope
Arduino_RFID_Sensor_Fun:14: error: 'LOW' was not declared in this scope
Arduino_RFID_Sensor_Fun:14: error: 'digitalWrite' was not declared in this scope
Arduino_RFID_Sensor_Fun.cpp: In function 'void loop()':
Arduino_RFID_Sensor_Fun:29: error: 'HIGH' was not declared in this scope
Arduino_RFID_Sensor_Fun:29: error: 'digitalWrite' was not declared in this scope
Arduino_RFID_Sensor_Fun:30: error: 'delay' was not declared in this scope
Arduino_RFID_Sensor_Fun:31: error: 'LOW' was not declared in this scope
Arduino_RFID_Sensor_Fun:36: error: 'Serial' was not declared in this scope
Arduino_RFID_Sensor_Fun.cpp: In function 'void ReadRFIDTag()':
Arduino_RFID_Sensor_Fun:42: error: 'Serial' was not declared in this scope
Arduino_RFID_Sensor_Fun:65: error: 'HIGH' was not declared in this scope
Arduino_RFID_Sensor_Fun:65: error: 'digitalWrite' was not declared in this scope
Arduino_RFID_Sensor_Fun:66: error: 'delay' was not declared in this scope
Arduino_RFID_Sensor_Fun.cpp: In function 'void AuthDeauthTag(char*)':
Arduino_RFID_Sensor_Fun:93: error: 'Serial' was not declared in this scope
Arduino_RFID_Sensor_Fun:98: error: 'Serial' was not declared in this scope

For this code:

//---------- RFID Stuff -----------\\
int  val = 0; 
char code[10]; 
int bytesread = 0; 
bool Auth;

// Tag variables
char Tag1[10] = {'1','2','0','0','0','C','8','9','8','5'}; // What Tag 1 returns on Serial
char Tag2[10] = {'1','2','0','0','0','C','8','B','0','8'}; // What Tag 2 returns on Serial

void setup() 
{
  Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps 
  pinMode(2,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin 
  digitalWrite(2, LOW);                  // Activate the RFID reader
  Serial.println("Scan your RFID Tag");
  while(!(Serial.available() > 0))
  {
    // Wait for Serial to return values (A.K.A. Wait for the card)
  }
  ReadRFIDTag();
  AuthDeauthTag(Tag1);
}


 void loop() 
{ 
  if(Auth == true)
  {
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(1000);
  }
  else
  {
    Serial.println("Done");
  }
}

void ReadRFIDTag()
{
  if(Serial.available() > 0) {          // if data available from reader 
    if((val = Serial.read()) == 10) 
    {                                   // check for header 
      bytesread = 0; 
      while(bytesread<10) 
      {                                  // read 10 digit code 
        if( Serial.available() > 0) 
        { 
          val = Serial.read(); 
          if((val == 10)||(val == 13)) 
          {                              // if header or stop bytes before the 10 digit reading 
            break;                       // stop reading 
          } 
          code[bytesread] = val;         // add the digit           
          bytesread++;                   // ready to read next digit  
        } 
      } 
      if(bytesread == 10) 
      {                                  // if 10 digit read is complete 
        Serial.print("TAG code is: ");   // possibly a good TAG 
        Serial.println(code);            // print the TAG code
      } 
      bytesread = 0; 
      digitalWrite(2, HIGH);             // deactivate the RFID reader for a moment so it will not flood
      delay(1500);                       // wait for a bit 
      //digitalWrite(2, LOW);         // Activate the RFID reader
    } 
  }
}

bool isArrayEqual(char array1[10], char array2[10])
{
  for(int i = 0; i < 10; i++)
  {
    if(array1[i] == array2[i])
    {
      // Continue on
    }
    else
    {
      return false;
      break;
    }
  }
  return true;
}

void AuthDeauthTag(char ID[10])
{  
  if(isArrayEqual(code, ID))
  {
    Serial.println("Autherized");
    Auth = true;
  }
  else
  {
    Serial.println("Booted");
    Auth = false;
  }
}

Help?

Change it to a pde extension, or add #include<WProgram.h> at the top.

Just remove the comment from the first line of the file - it messes up the preprocessor.

EDIT: Actually, it seems like it's just the backslash in the comment that's problematic; comments without the backslashes are fine.

Is this documented somewhere?

[quote author=Professor Chaos link=topic=63719.msg463524#msg463524 date=1307821692] ...it seems like it's just the backslash in the comment that's problematic; comments without the backslashes are fine.[/quote]

In C and C++ code (certain other languages, too), if the last character on a line is a backslash (the last character before the newline, that is), the following line is treated as a continuation. The C++ sketch generated by Arduino puts #include "Wprogram.h" after initial comments and before the function prototypes, so the first two lines of the generated sketch are

//---------- RFID Stuff -----------\\
#include "WProgram.h"

The C++ preprocessor stitches the two lines together into a single line like this:

//---------- RFID Stuff -----------\#include "WProgram.h"

so that the #include stuff is now part of the comment. The C++ preprocessor throws away all comments so the compiler never sees the #include "Wprogram" line, and that's what causes these particular errors.

Ways to avoid problems like this:

1. Don't write comments with backslash as the final character on the line. (Note that blank characters after a '\' at the end are absorbed by some compiler preprocessors, including the one for avr-gcc used by Arduino, so you can't expect to improve it by just adding a space or two after the backslash.)

or

2. If you feel that you absolutely must have a backslash as the last character of a comment, leave at least one blank line or a non-backslashed one-line comment line (or some such thing) between the backslashed comment and anything significant.

These little rules apply to all C and C++ programs, not just Arduino sketches. These apply to any part of a program, not just the first line. (It's not an Arduino thing; it's a C/C++ thing.)

Regards,

Dave

Thank you all for helping! Removing the back slashes worked great!