digitalmars.D.learn - bug? for(int i=0;i<1;) vs while(true)
- ddos (15/15) Sep 17 2015 http://pastebin.com/fknwgjtz
- ddos (1/1) Sep 17 2015 using DMD32 D Compiler v2.068.0 on windows x64
- Adam D. Ruppe (7/8) Sep 17 2015 What's there? Anything after an endless loop is potentially
- ddos (3/5) Sep 17 2015 i see, thx
- H. S. Teoh via Digitalmars-d-learn (12/30) Sep 17 2015 Maybe just write:
- ddos (7/38) Sep 17 2015 yeah i tried for(;;) and it generates the same warning :)
- Adam D. Ruppe (4/9) Sep 17 2015 Yeah, it is the return 0 at the bottom. You can actually just
- ddos (1/1) Sep 18 2015 thank you :) works now
- Kagamin (8/8) Sep 18 2015 This compiles with enabled warnings:
- Timon Gehr (5/11) Sep 17 2015 Remove the return statement from main and the warning will go away.
http://pastebin.com/fknwgjtz i tried to call fibers in a loop forever, to multiplex some networking client worker fibers and a listener fiber it seems to work correctly with for(int i=0;i<1;) with while(true) i get: C:\dev\server_client>dub Building server_client ~master configuration "application", build type debug. Compiling using dmd... source\app.d(72): Warning: statement is not reachable FAIL .dub\build\application-debug-windows-x86-dmd_2068-32A80D3C074EAD350DDE74DB2 61C6BB5\ server_client executable Error executing command run: dmd failed with exit code 1.
Sep 17 2015
On Thursday, 17 September 2015 at 19:32:16 UTC, ddos wrote:source\app.d(72): Warning: statement is not reachableWhat's there? Anything after an endless loop is potentially unreachable and dub treats warnings as errors. With the for loop, the compiler can't be as sure that it is endless because plain for loops often have their variable changed inside and the compiler just isn't smart enough to actually check for that too.
Sep 17 2015
On Thursday, 17 September 2015 at 19:35:05 UTC, Adam D. Ruppe wrote:What's there? Anything after an endless loop is potentially unreachable and dub treats warnings as errors.i see, thx
Sep 17 2015
On Thu, Sep 17, 2015 at 07:32:13PM +0000, ddos via Digitalmars-d-learn wrote:http://pastebin.com/fknwgjtz i tried to call fibers in a loop forever, to multiplex some networking client worker fibers and a listener fiber it seems to work correctly with for(int i=0;i<1;) with while(true) i get: C:\dev\server_client>dub Building server_client ~master configuration "application", build type debug. Compiling using dmd... source\app.d(72): Warning: statement is not reachable FAIL .dub\build\application-debug-windows-x86-dmd_2068-32A80D3C074EAD350DDE74DB2 61C6BB5\ server_client executable Error executing command run: dmd failed with exit code 1.Maybe just write: for (;;) { ... } instead? You can read `(;;)` as "ever". :-P Also, could you post a (possibly reduced) code example that can be compiled? It's kinda hard to figure out what's wrong when the code in the paste is incomplete. T -- Любишь кататься - люби и саночки возить.
Sep 17 2015
On Thursday, 17 September 2015 at 19:43:02 UTC, H. S. Teoh wrote:On Thu, Sep 17, 2015 at 07:32:13PM +0000, ddos via Digitalmars-d-learn wrote:yeah i tried for(;;) and it generates the same warning :) sure, here is the full example, it's not too long anyways ( the example doesn't make much sense tho because socket.accept is blocking :P ) http://pastebin.com/9K0wRRD6 ps: pastebin needs D support :-Dhttp://pastebin.com/fknwgjtz i tried to call fibers in a loop forever, to multiplex some networking client worker fibers and a listener fiber it seems to work correctly with for(int i=0;i<1;) with while(true) i get: C:\dev\server_client>dub Building server_client ~master configuration "application", build type debug. Compiling using dmd... source\app.d(72): Warning: statement is not reachable FAIL .dub\build\application-debug-windows-x86-dmd_2068-32A80D3C074EAD350DDE74DB2 61C6BB5\ server_client executable Error executing command run: dmd failed with exit code 1.Maybe just write: for (;;) { ... } instead? You can read `(;;)` as "ever". :-P Also, could you post a (possibly reduced) code example that can be compiled? It's kinda hard to figure out what's wrong when the code in the paste is incomplete. T
Sep 17 2015
On Thursday, 17 September 2015 at 19:47:15 UTC, ddos wrote:yeah i tried for(;;) and it generates the same warning :) sure, here is the full example, it's not too long anyways ( the example doesn't make much sense tho because socket.accept is blocking :P ) http://pastebin.com/9K0wRRD6Yeah, it is the return 0 at the bottom. You can actually just remove that and make main return void instead. (That's perfectly legal in D, different than C)
Sep 17 2015
This compiles with enabled warnings: --- int f() { while(true){} assert(false); } ---
Sep 18 2015
On 09/17/2015 09:47 PM, ddos wrote:yeah i tried for(;;) and it generates the same warning :) sure, here is the full example, it's not too long anyways ( the example doesn't make much sense tho because socket.accept is blocking :P ) http://pastebin.com/9K0wRRD6 ps: pastebin needs D support :-DRemove the return statement from main and the warning will go away. (Note: unless you want to influence the return code, you can actually declare main as returning void, then you don't need it even if the end of the function is reachable.)
Sep 17 2015