I was wondering if you can have two 'break' in one case with a switch function.
For Example:
switch(menu)
case1:
code
break
code
break
case2:
Is this allowed in C.
I was wondering if you can have two 'break' in one case with a switch function.
For Example:
switch(menu)
case1:
code
break
code
break
case2:
Is this allowed in C.
Yes, but that second line of code will likely be unreachable.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Hi it works, but i am wondering where do you need such applications?
its no of use.
Regards,
Shwetha
basically im writing a program for a user calender operation, i wanted to use the 'break' function to end the case if the user entered an invalid date, for example.
thanks for your help
There are at least two applications:
The nasty one is performing initialization tasks for the next case, if you got there with the goto statement. When Rob Pike says that the goto statement is useful under certain circumstances, he certainly didn't have this technique in mind, so we better forget about it immediately.
The other application is making two branches have the same size in the resulting binary in order to separate execution duration from code length. This is so even if I know how long the program took to execute a certain branch, I don't know which branch it was until I fully understood the code in all branches (i.e. no automatic algorithm which matches execution duration and code length). A similar technique involves if-statements where the conditional expression always evaluates to false (to increase code size) or code which only performs irrelevant computations (to increase execution duration). Both of these are a common technique in proprietary software to make it harder to understand the disassembled code (Microsoft's operating system binaries are full of this stuff).
Along those lines, I once wrote a program for the DFKI (which probably means "German Research Center for Artificial Intelligence" in English) which was able to determine key events (keypress/keyrelease, and partly even the corresponding keys) by only examining CPU usage and exploiting several facts about the CPU's cache, the layout of the keymap and so on. Without the execution duration of all the branches in the corresponding key event interrupt service routine being equal, I can (as a regular user) make highly sophisticated guesses about other people's passwords, e.g. the admin password.
This should tell you two things:
- don't give me access to your computer
- you don't need fake code if you're not working for the NSA
Greets,
Philip
All things begin as source code.
Source code begins with an empty file.
-- Tao Te Chip