TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DARIN MCBRIDE
from: MATHIEU BOUCHARD
date: 1997-08-28 07:02:00
subject: Why the braces?

 NH>> switch (foo) {
 NH>> case 1 :
 NH>> int bar = 2;
 NH>> break;
 NH>> case 2 :
 NH>> int bar = 3;
 NH>> break;
 NH>> }
 DM> What are the compiler errors?  IIRC, without jumping around to my 
 DM> compilers,
 DM> I believe you'd get something along the lines of jumping over the
 DM> initialization of bar.  If you'd rename them to bar1 and bar2, you'd 
 DM> notice
 DM> that your case 2 jumps past the initialization of bar1.  That's because 

 DM> switch is basically a glorified goto - and bar1 is still in scope at 
case 
 DM> 2.
in C/C++, lack of initialization is not an error. the error is that
there are two identical variable names.
matju
--- Terminate 4.00/Pro
---------------
* Origin: The Lost Remains Of SatelliteSoft BBS (1:163/215.42)

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