TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JONATHAN DE BOYNE POLLARD
from: DARIN MCBRIDE
date: 1998-03-04 20:31:00
subject: C++ Saveding stuff

 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)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.