digitalmars.D - More "switch/default" woes
- Matthew (31/31) Feb 26 2005 Can anyone figure out why the following doesn't cause two combo boxs to
- John C (4/33) Feb 26 2005 I don't think the code is reachable. There's a break after the first com...
- Matthew (2/37) Feb 26 2005
- Nick Sabalausky (2/46) Feb 26 2005
- Walter (7/10) Feb 26 2005 no!
- John Reimer (2/21) Feb 26 2005 Time for another compiler switch? ;-)
- Matthew (12/25) Feb 26 2005 Yet again, my friend, you're prescribing behaviour with enormous
- Manfred Nowak (19/20) Feb 27 2005 No. I assist Walter with another argument: You wrote `break'---so
- Regan Heath (22/41) Feb 27 2005 True.
- Matthew (3/10) Feb 28 2005 No-one's saying it is.
- Ben Hinkle (9/19) Feb 27 2005 What exactly are you requesting? Is it a warning about unreachable code?
- Manfred Nowak (5/6) Feb 27 2005 [...]
- Walter (20/30) Feb 27 2005 D can't help but be a reflection of my personal experience and developme...
- Matthew (2/13) Feb 28 2005 Why so? Isn't it actually a good thing for the compiler to nag you to fi...
Can anyone figure out why the following doesn't cause two combo boxs to be displayed. I am, as I suspect Kris will also be, sighing deeply extern (Windows) LPARAM wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_CREATE: HWND comboBoxHandle = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 10, 10, 150, 100, hWnd, null, null, null); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item one")); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item two")); break; HWND comboBoxHandle2 = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 200, 200, 150, 100, hWnd, null, null, null); default: break; } return DefWindowProcA(hWnd, uMsg, wParam, lParam); }
Feb 26 2005
I don't think the code is reachable. There's a break after the first combo box is created. "Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:cvppqg$6ge$1 digitaldaemon.com...Can anyone figure out why the following doesn't cause two combo boxs to be displayed. I am, as I suspect Kris will also be, sighing deeply extern (Windows) LPARAM wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_CREATE: HWND comboBoxHandle = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 10, 10, 150, 100, hWnd, null, null, null); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item one")); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item two")); break; HWND comboBoxHandle2 = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 200, 200, 150, 100, hWnd, null, null, null); default: break; } return DefWindowProcA(hWnd, uMsg, wParam, lParam); }
Feb 26 2005
Exactly. But did the compiler balk on it, with a helpful message? No, and no! "John C" <johnch_atms hotmail.com> wrote in message news:cvq1q3$h6o$1 digitaldaemon.com...I don't think the code is reachable. There's a break after the first combo box is created. "Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:cvppqg$6ge$1 digitaldaemon.com...Can anyone figure out why the following doesn't cause two combo boxs to be displayed. I am, as I suspect Kris will also be, sighing deeply extern (Windows) LPARAM wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_CREATE: HWND comboBoxHandle = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 10, 10, 150, 100, hWnd, null, null, null); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item one")); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item two")); break; HWND comboBoxHandle2 = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 200, 200, 150, 100, hWnd, null, null, null); default: break; } return DefWindowProcA(hWnd, uMsg, wParam, lParam); }
Feb 26 2005
Yea, that looks like a good place for an "unreachable code" error. Matthew wrote:Exactly. But did the compiler balk on it, with a helpful message? No, and no! "John C" <johnch_atms hotmail.com> wrote in message news:cvq1q3$h6o$1 digitaldaemon.com...I don't think the code is reachable. There's a break after the first combo box is created. "Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:cvppqg$6ge$1 digitaldaemon.com...Can anyone figure out why the following doesn't cause two combo boxs to be displayed. I am, as I suspect Kris will also be, sighing deeply extern (Windows) LPARAM wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); break; case WM_CREATE: HWND comboBoxHandle = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 10, 10, 150, 100, hWnd, null, null, null); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item one")); SendMessageA(comboBoxHandle, CB_ADDSTRING, 0, cast(LPARAM)toStringz("Item two")); break; HWND comboBoxHandle2 = CreateWindowExA(0, "COMBOBOX", "", WS_CHILD | WS_VISIBLE | CBS_DROPDOWN | CBS_HASSTRINGS, 200, 200, 150, 100, hWnd, null, null, null); default: break; } return DefWindowProcA(hWnd, uMsg, wParam, lParam); }
Feb 26 2005
"Matthew" <admin.hat stlsoft.dot.org> wrote in message news:cvr6lh$1ndv$1 digitaldaemon.com...Exactly. But did the compiler balk on it, with a helpful message? No, andno!"John C" <johnch_atms hotmail.com> wrote in messagenews:cvq1q3$h6o$1 digitaldaemon.com...combo box is created. I tend to generate lots of unreachable code when trying to isolate a problem. It's a nuisance having the compiler complain about it.I don't think the code is reachable. There's a break after the first
Feb 26 2005
Walter wrote:"Matthew" <admin.hat stlsoft.dot.org> wrote in message news:cvr6lh$1ndv$1 digitaldaemon.com...Time for another compiler switch? ;-)Exactly. But did the compiler balk on it, with a helpful message? No, andno!"John C" <johnch_atms hotmail.com> wrote in messagenews:cvq1q3$h6o$1 digitaldaemon.com...combo box is created. I tend to generate lots of unreachable code when trying to isolate a problem. It's a nuisance having the compiler complain about it.I don't think the code is reachable. There's a break after the first
Feb 26 2005
Yet again, my friend, you're prescribing behaviour with enormous ramifications on the entire (current and potential) D community as a result of your own personal experience and development style. I have to say, as I've said many times before, that I think this is a bad general strategy, and this is a specific acute example of it. I had actually forgotten the 'deliberate' nature of this, and was feeling a little Kris-guilt at having made too much of a big deal about what was obviously a (temporary) compiler error. Now I realise the full horror of it, I realise I was far too easy on it. This is bad stuff. :-( Matthew "Walter" <newshound digitalmars.com> wrote in message news:cvrhvs$2222$1 digitaldaemon.com..."Matthew" <admin.hat stlsoft.dot.org> wrote in message news:cvr6lh$1ndv$1 digitaldaemon.com...Exactly. But did the compiler balk on it, with a helpful message? No, andno!"John C" <johnch_atms hotmail.com> wrote in messagenews:cvq1q3$h6o$1 digitaldaemon.com...combo box is created. I tend to generate lots of unreachable code when trying to isolate a problem. It's a nuisance having the compiler complain about it.I don't think the code is reachable. There's a break after the first
Feb 26 2005
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote: [...]This is bad stuff. :-(No. I assist Walter with another argument: You wrote `break'---so you meant `break'. It is not the job of the compiler to declare some code as erroneous when you expressively wanted it. Otherwise what would D end in? Adding the `default' case to a `switch' statement is an error because the other cases cover all possible values and therefore the code of the `default' case is unreachable? `if(e())return; <code>' is an error because the function `e' can be proved to compute `true' and therefore <code> is unreachable? `version(null)' without an `else' is an error because this version may not be set at the command line and therefore the code may be unreachable? Unused variable? Unused member of a class? Unused class when importing a module? Linking to a library only possible if you use all and every construct in the library? -manfred
Feb 27 2005
On Sun, 27 Feb 2005 08:43:41 +0000 (UTC), Manfred Nowak <svv1999 hotmail.com> wrote:"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote: [...]True. IMO Matthews point was that the compiler should detect 'accidental' unreachable code. i.e. switch() { case x: if (a); <-accidental semi-colon break; ..unreachable.. ..etc.. Note: The above is actually illegal D, as ; is not a valid empty statement {} must be used instead, so, the good news is that D does detect the accidental break, in this case. Are there other examples of accidental unreachable code where the root cause is actually something else, like the ; {} thing above?This is bad stuff. :-(No. I assist Walter with another argument: You wrote `break'---so you meant `break'. It is not the job of the compiler to declare some code as erroneous when you expressively wanted it.Otherwise what would D end in? Adding the `default' case to a `switch' statement is an error because the other cases cover all possible values and therefore the code of the `default' case is unreachable? `if(e())return; <code>' is an error because the function `e' can be proved to compute `true' and therefore <code> is unreachable? `version(null)' without an `else' is an error because this version may not be set at the command line and therefore the code may be unreachable? Unused variable? Unused member of a class? Unused class when importing a module? Linking to a library only possible if you use all and every construct in the library?I agree with you "In the general case it is undecidable, whether code is reachable." However, it's possible (as in my example above) to detect the error that causes the unreachable code, meaning the programmer can still intentionally do it, but is less likely to accidentally do it. Regan
Feb 27 2005
"Manfred Nowak" <svv1999 hotmail.com> wrote in message news:cvs17s$2hoh$1 digitaldaemon.com..."Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote: [...]Yeah, but there was no case!This is bad stuff. :-(No. I assist Walter with another argument: You wrote `break'---so you meant `break'.It is not the job of the compiler to declare some code as erroneous when you expressively wanted it.No-one's saying it is.
Feb 28 2005
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:cvrknn$250a$1 digitaldaemon.com...Yet again, my friend, you're prescribing behaviour with enormous ramifications on the entire (current and potential) D community as a result of your own personal experience and development style. I have to say, as I've said many times before, that I think this is a bad general strategy, and this is a specific acute example of it. I had actually forgotten the 'deliberate' nature of this, and was feeling a little Kris-guilt at having made too much of a big deal about what was obviously a (temporary) compiler error. Now I realise the full horror of it, I realise I was far too easy on it. This is bad stuff. :-( MatthewWhat exactly are you requesting? Is it a warning about unreachable code? Imagine an editor that would color unreachable code in a special color before you ever compile it. It shouldn't be too hard to do with with a dlint and an editor that lets you run a program and color text as a result. I tell you, an integrated lint is better than warnings. Complex control flow might be hard for a dlint to detect but a simple thing like two breaks in a case would be easy.
Feb 27 2005
"Ben Hinkle" <ben.hinkle gmail.com> wrote: [...]Complex control flow might be hard for a dlint to detect[...] In the general case it is undecidable, whether code is reachable. -manfred
Feb 27 2005
"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message news:cvrknn$250a$1 digitaldaemon.com...Yet again, my friend, you're prescribing behaviour with enormous ramifications on the entire (current and potential) D community as a result of your own personal experience and development style. I have to say, as I've said many times before, that I think this is a bad general strategy, and this is a specific acute example of it.D can't help but be a reflection of my personal experience and development style, just as C, C++, Ruby, Python, Perl, etc., are each a reflection of their principal designers.I had actually forgotten the 'deliberate' nature of this, and was feeling a little Kris-guilt at having made too much of a big deal about what was obviously a (temporary) compiler error.You argue for the compiler to complain about dead code in some circumstances, but require the programmer to insert dead code in other circumstances (the switch default, and the fallthrough return). Trying to simultaneously codify both into the language rules would be tricky.Now I realise the full horror of it, I realise I was far too easy on it. This is bad stuff. :-(The following code is perfectly legal C++, too: int foo() { return 1; return 2; } There are many horrors in C++, but that one isn't. While it's "obviously" wrong, there are many more subtle cases where things aren't so clear (many popular compilers generate spurious and erroneous warnings about supposedly dead code), and as I posted before, sometimes it is convenient to allow such when trying to rapidly develop/test/debug code.
Feb 27 2005
"Walter" <newshound digitalmars.com> wrote in message news:cvrhvs$2222$1 digitaldaemon.com..."Matthew" <admin.hat stlsoft.dot.org> wrote in message news:cvr6lh$1ndv$1 digitaldaemon.com...Why so? Isn't it actually a good thing for the compiler to nag you to fix up something which you admit is temporary?Exactly. But did the compiler balk on it, with a helpful message? No, andno!"John C" <johnch_atms hotmail.com> wrote in messagenews:cvq1q3$h6o$1 digitaldaemon.com...combo box is created. I tend to generate lots of unreachable code when trying to isolate a problem. It's a nuisance having the compiler complain about it.I don't think the code is reachable. There's a break after the first
Feb 28 2005