1
int parity = 1;
// DATA, PARITY, and STOP BITS SETTINGS
#if parity == 1 
    #define PARITY SERIAL_8N1
#elif parity == 2
    #define PARITY SERIAL_8O1

void setup()
{
  Serial.begin(9600, PARITY)
}

void loop()
{
  Serial.print(parity);
  Serial.print("PARITY");
}

#endif

Error -

/home/akshulg/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/main.cpp:43: undefined reference to `setup'
/home/akshulg/Downloads/arduino-1.8.5-linux64/arduino-1.8.5/hardware/arduino/avr/cores/arduino/main.cpp:46: undefined reference to `loop'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino/Genuino Uno.

If I am using this code -

int parity = 1;
// DATA, PARITY, and STOP BITS SETTINGS
#if parity == 1 
    #define PARITY SERIAL_8N1
#elif parity == 2
    #define PARITY SERIAL_8O1
#endif
void setup()
{
  Serial.begin(9600, PARITY)
}

void loop()
{
  Serial.print(parity);
  Serial.print("PARITY");
}

Error -

error: 'PARITY' was not declared in this scope
   Serial.begin(9600, PARITY)
                      ^
exit status 1
'PARITY' was not declared in this scope
3
  • You cannot use variables if preprocessor directives like #if. You need to use a preprocessor constant, which is available for the preprocessor, meaning a #define. As reference look at this question at SO – chrisl Feb 16 at 9:14
  • 3
    I’m voting to close this question because this is about C/C++ syntax and not about Arduino. Also a fitting SO answer is linked in the comment above. – chrisl Feb 16 at 9:15
  • 1
    Thanks for the link. Will refer that. – Robot Feb 16 at 9:33