user19573: The "DumpFile.ino" example sketch from the SD library tries to open a file off an SD card, read its contents, and write them to the Serial Monitor. I am confused in how the following if() statement is evaluated:
File dataFile = SD.open("datalog.txt");

if (dataFile) {
// read and print, then close
}
else {
// print error message
}

There must be some implicit conversion on dataFile which depends on whether or not SD.open("myFile.txt") was successful. I would like to understand how this implicit conversion occurs. Which property of the File object determines if the if() statement evaulates true or false?

user10794: There is an operator bool which does the test:
File::operator bool() {
  if (_file) 
    return  _file->isOpen();
  return false;
}

When used inside an if the compiler invokes the operator bool() which does the test you see above.

19573: <p>The "DumpFile.ino" example sketch from the SD library tries to open a file off an SD card, read its contents, and write them to the Serial Monitor. I am confused in how the following <code>if()</code> statement is evaluated:</p>

<pre><code>File dataFile = SD.open("datalog.txt");

if (dataFile) {
// read and print, then close
}
else {
// print error message
}
</code></pre>

<p>There must be some implicit conversion on <code>dataFile</code> which depends on whether or not <code>SD.open("myFile.txt")</code> was successful. I would like to understand how this implicit conversion occurs. Which property of the <code>File</code> object determines if the <code>if()</code> statement evaulates <code>true</code> or <code>false</code>?</p>
 10794: <p>There is an operator bool which does the test:</p>

<pre><code>File::operator bool() {
  if (_file) 
    return  _file-&gt;isOpen();
  return false;
}
</code></pre>

<p>When used inside an <code>if</code> the compiler invokes the <code>operator bool()</code> which does the test you see above.</p>
