TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: NEIL HELLER
from: THOMAS MAEDER
date: 1997-08-26 18:18:00
subject: Why the braces?

NH> However, if I write the code this way there are no errors:
NH> switch (foo) {
NH>     case 1 : {
NH>         int bar = 2;
NH>         break;
NH>     }
NH>     case 2 : {
NH>         int bar = 3;
NH>         break;
NH>     }
NH> }
NH> I was under the assumption that the braces weren't necessary in C++
NH> far as declaring variables is concerned.  Why then do I need the
NH> braces?  Do the added braces affect portability in any way?
Yes, only correct code is portable :-)
What's  your  problem  with writing two additional characters? Does it
help you if I tell you that well designed code  doesn't  contain  many
switch statements?
Thomas
---
 þ MM 1.0 #0113 þ That light at the end of the tunnel is a train....
---------------
* Origin: McMeier & Son BBS (2:301/138)

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™.