Thread overview
bug? for(int i=0;i<1;) vs while(true)
Sep 17, 2015
ddos
Sep 17, 2015
ddos
Sep 17, 2015
Adam D. Ruppe
Sep 17, 2015
ddos
Sep 17, 2015
H. S. Teoh
Sep 17, 2015
ddos
Sep 17, 2015
Adam D. Ruppe
Sep 18, 2015
ddos
Sep 18, 2015
Kagamin
Sep 17, 2015
Timon Gehr
September 17, 2015
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.
September 17, 2015
using DMD32 D Compiler v2.068.0 on windows x64
September 17, 2015
On Thursday, 17 September 2015 at 19:32:16 UTC, ddos wrote:
> source\app.d(72): Warning: statement is not reachable

What'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.
September 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

-- 
Любишь кататься - люби и саночки возить.
September 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
September 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:
>> 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

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 :-D

September 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/9K0wRRD6

Yeah, 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)

September 17, 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 :-D

Remove 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.)
September 18, 2015
thank you :) works now
September 18, 2015
This compiles with enabled warnings:
---
int f()
{
	while(true){}
	assert(false);
}
---