user23991: The following program compiles in the Arduino IDE.
void doSomething(bool) {}

void setup() {      
  doSomething(Serial);
}

void loop() {}

But, as expected, this one doesn't:
class MyClass {};

void doSomething(bool) {}

void setup() {   
  MyClass myClass;
  doSomething(myClass);
}

void loop() {}

The compiler returns the error cannot convert 'MyClass' to 'bool' for argument '1' to 'void doSomething(bool)'

Why is it possible to compile the former? Isn't Serial a normal class instance (of HardwareSerial)? Does it makes any sense to interpret Serial as a bool?

user368: HardwareSerial defines operator bool(), which allows it to be used in a boolean context.

23991: <p>The following program compiles in the Arduino IDE.</p>

<pre><code>void doSomething(bool) {}

void setup() {      
  doSomething(Serial);
}

void loop() {}
</code></pre>

<p>But, as expected, this one doesn't:</p>

<pre><code>class MyClass {};

void doSomething(bool) {}

void setup() {   
  MyClass myClass;
  doSomething(myClass);
}

void loop() {}
</code></pre>

<p>The compiler returns the error <code>cannot convert 'MyClass' to 'bool' for argument '1' to 'void doSomething(bool)'</code></p>

<hr>

<p>Why is it possible to compile the former? Isn't Serial a normal class instance (of <code>HardwareSerial</code>)? Does it makes any sense to interpret <code>Serial</code> as a bool?</p>
 368: <p><code>HardwareSerial</code> <a href="http://en.cppreference.com/w/cpp/language/operators" rel="nofollow noreferrer">defines</a> <code>operator bool()</code>, which allows it to be used in a boolean context.</p>
