JdBP> Of course, the problem with this fact being widely
JdBP> unrecognised is that when one writes
JdBP> if (FILE * f = fopen("file.txt","r")) {
JdBP> // ...
JdBP> fclose(f) ;
JdBP> }
JdBP> in this echo, and one is then asked to move to the C
JdBP> echo, one moves there only to be told that this is
JdBP> incorrect C. (-:
Well, I would *hope* that whoever was bright enough to note that this was
C++-only code, would also note that the implicit check against NULL makes
this marginally confusing, and one would probably be better off moving the
declaration (and initialization) of f to before the if anyway.
FILE* f = fopen("file.txt","r");
if (NULL != f)
{
// ...
fclose(f);
}
Now this is much more readable (IMNSHO), and, as a bonus, legal C under the
proposed C9X. :-)
---
---------------
* Origin: Tanktalus' Tower BBS (1:250/102)
|