Difference between if(Serial.available()) and if(Serial.available()>0)

Difference between if(Serial.available()) and if(Serial.available()>0) and if(Serial.available()==0) guys please help. I really need to know the differences :confused: :confused: :confused:

https://www.arduino.cc/en/Serial/Available

https://www.arduino.cc/en/Reference/If

if (Serial.available()) is active if the result is true (non-zero), if (Serial.available() > 0) is active if the result greater than zero, if (Serial.available() == 0) is active if the result is zero,

But still not conclusively answering the OP’s question…

Is there any circumstance in which Serial.available()<0 ? ie Serial.available() is true but (Serial.available()>0) is false?

I’m not a C-coding expert but such functions tend towards the nasty habit of returning a negative number for certain kinds of error.

Look at the source code:

int HardwareSerial::available(void)
{
  return ((unsigned int)(SERIAL_RX_BUFFER_SIZE + _rx_buffer_head - _rx_buffer_tail)) % SERIAL_RX_BUFFER_SIZE;
}

Result is always positive, so no there is no differences between

if( Serial.available() )

and

if( Serial.available() > 0 )

But

if( Serial.available() == 0 )

is obviously the opposite of the above lines

Why many people use

if( Serial.available() > 0 )

?

Because it's more clear, since this function doesn't return true or false, but the # of characters in the buffer.