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

 -=> Quoting Mathieu Bouchard to Darin Mcbride
 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 
ase
 
 MB> in C/C++, lack of initialization is not an error. the error is that
 MB> there are two identical variable names.
Nope... both are errors.  Have you tried it on your compiler before posting,
or did you just post?  Try compiling an example, first...
... If you expect nothing, you won't be disappointed.
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)

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