Re: DMD: how to restore old unittest+main

2020-08-13 Thread Jonathan via Digitalmars-d-learn

On Thursday, 13 August 2020 at 07:52:07 UTC, novice3 wrote:

Hello.

I don't use dub.
I use Windows and *.d file association to compile small apps by 
dmd with "-i -unittest -g" switches.
Now i update dmd, and found, that apps compiled with 
"-unittest" not runs main().


How i can restore old behaviour (run all unittests then main())
*without use "--DRT-testmode=run-main" switch every time then i 
start compiled app.exe*?
I want just press Enter on app.d file, then press Enter on 
app.exe.

Any advises?

Thanks.


Is there a reason you need to run all unittests every time you 
want to run the program?


I personally compile with -unittest to make sure all my unittests 
pass, then recompile without the -unittest flag if I actually 
want to run the program.  This way, time isn't wasted running 
unittests every time the program is run.


Use std.traits.getSymbolsByUDA to access members of instance.

2018-10-01 Thread Jonathan via Digitalmars-d-learn
I can use `std.traits.getSymbolsByUDA` to get all the members of 
a class that have a particular UDA `getSymbolsByUDA(ValueType, 
UDA)`.


But how do I get the values with it?

Is there a more convenient way than `__traits(getMember, value, 
getSymbolsByUDA(ValueType, UDA)[0].stringof)`?


Calling nested function before declaration

2018-09-26 Thread Jonathan via Digitalmars-d

This code fails to compile: ("undefined identifier fun")
void main() {
fun();
void fun() {}
}

Having the call after the declaration works:
void main() {
void fun() {}
fun();
}

Is this how it is intended to work?

It seems goofy that this works:
void main() {
void fun2() {}
void fun() {
 fun2()
}
fun();
}

But this fails to compile: ("undefined identifier fun2")
void main() {
void fun() {
 fun2()
}
void fun2() {}
fun();
}

What if I wanted this?
void main() {
void fun2() {fun();}
void fun() {fun2();}
fun();
}

I can't see how the current behavior is at all better or to be 
preferred unless it is faster to compile?  What is the reason for 
it being how it is?


Re: On Forum Moderation

2018-05-25 Thread Jonathan via Digitalmars-d

On Saturday, 26 May 2018 at 03:34:50 UTC, Walter Bright wrote:

From time to time, the issue comes up.

The standard here is professional demeanor. For what 
professional demeanor is, see:


https://www.amazon.com/Etiquette-Society-Business-Politics-Home/dp/1497339979

Unprofessional demeanor will get removed at the forum staff's 
sole discretion on a case by case basis, as well as replies to 
it.


For unprofessional demeanor, I recommend reddit.


+1


Re: Ideas for students' summer projects

2018-05-22 Thread Jonathan via Digitalmars-d

On Wednesday, 23 May 2018 at 01:51:35 UTC, Mike Franklin wrote:

Make WebAssembly a thing in D.


Yes please!

I would love to help with WebAssembly in D but frankly it is a 
little it overwhelming me and my lack of knowledge.  If anyone 
does take the bull by the horns, let me know if you need a noobs 
help (:


`free` for struct with C bindings.

2018-05-14 Thread Jonathan via Digitalmars-d-learn
I am using a C bindings library 
(https://code.dlang.org/packages/xcb-d).


I am following through a tutorial that was written for the C 
library directly and just making the minor changes to make it 
work with D.


I ran into a problem. The library ends up giving me a struct 
pointer.


```
xcb_generic_event_t*event;
event = xcb_wait_for_event (connection);
free (event);
```

The problem is the `free` function.  It is not provided by the 
library but is part of the C standard library (in stdlib.h).


Do I need to call this function with my D code?  I tried using 
the `core.memory.GC.free` function from the D standard library 
and it compiled and ran but that does not necessarily mean there 
are not memory leaks (it also ran with the line entirely removed).


Do I need to call the `free` function with my D code because I 
need to free memory that was allocated in C code?


Arguments of function as an array.

2018-04-26 Thread Jonathan via Digitalmars-d-learn
Is there a way in D to take past arguments as an array?  A like a 
normal Variadic function.  All the arguments should be of the 
same type just as an array.


Basically I want to allow a function like this to be called 
without square brackets.


void fun(int[] intArray) {
//...
}
void main() {
fun([5,6,4]);
}

Like  this:

void fun(int... intArray) {
//typeof(intArray) is `int[]`
}
void main() {
fun(5,6,4);
}

Is this doable in D?


Re: Strange Thread Causing Duplicating `writeln`

2018-04-11 Thread Jonathan via Digitalmars-d-learn
On Tuesday, 10 April 2018 at 23:59:08 UTC, Steven Schveighoffer 
wrote:

On 4/9/18 6:56 PM, Jonathan wrote:

On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:

On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:
I don't know, but I can't reproduce either with dmd or ldc. 
What was your compilation line?


dmd -run file.d


I am on Window 10 btw.


It's a windows 32-bit issue (specifically, DMC's FILE *, upon 
which std.stdio.File is based, is thread unsafe).


Try -m64.

https://issues.dlang.org/show_bug.cgi?id=18483
http://bugzilla.digitalmars.com/issues/show_bug.cgi?id=327

-Steve


Hum, thank you.


Re: Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn

On Monday, 9 April 2018 at 22:56:33 UTC, Jonathan wrote:

On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:

On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:
I don't know, but I can't reproduce either with dmd or ldc. 
What was your compilation line?


dmd -run file.d


I am on Window 10 btw.


Hum, LDC does not do it for me?


Re: Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn

On Monday, 9 April 2018 at 22:53:31 UTC, Jonathan wrote:

On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:
I don't know, but I can't reproduce either with dmd or ldc. 
What was your compilation line?


dmd -run file.d


I am on Window 10 btw.


Re: Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn

On Monday, 9 April 2018 at 22:49:07 UTC, Cym13 wrote:
I don't know, but I can't reproduce either with dmd or ldc. 
What was your compilation line?


dmd -run file.d


Strange Thread Causing Duplicating `writeln`

2018-04-09 Thread Jonathan via Digitalmars-d-learn

I am totally lost on why this is happening.

I stripped the code down to what appears to be the most minimal 
code that still causes the problem.


---
import core.sync.mutex;
import core.thread;
import std.stdio;

__gshared Mutex m;//__gshared just for testing (;

void thread1() {
foreach (i;0..8) {
synchronized(m) {
writeln("a1-",i);
}
writeln("a2-",i);
}
}
void thread2() {
foreach (i;0..8) {
synchronized(m) {
writeln("b1-",i);
}
writeln("b2-",i);
}
}


void main() {
m = new Mutex();

new Thread().start;
new Thread().start;
}
---
The beginning of the output for this code is:
a1-0
a2-0
a2-0
b1-0
b2-0
b2-0
a1-1
a2-1
a2-1

Why is the "a2" and "b2" writeln being repeated?!


Atomic vs Mutex

2018-03-26 Thread Jonathan via Digitalmars-d-learn
Everywhere I look the advice is to avoid atomic and just mutex 
things.


Why is this `a.atomicStore(b)`(memory order is seq) less safe 
than `synchronized{a=b}`?  I get that when more operations or 
shared values are used it is appropriate to mutex the entire set 
of operations but why would I for a single set?


If the first is in fact less safe that the second then I am eager 
to learn more, could you recommend a book or paper on the subject?


Thanks!


Re: Is socket.send thread safe?

2018-03-26 Thread Jonathan via Digitalmars-d-learn

On Monday, 26 March 2018 at 17:55:10 UTC, bauss wrote:

On Monday, 26 March 2018 at 16:14:31 UTC, Jonathan wrote:
Can I send data over an std.socket on multiple threads without 
manual mutexing?


If not, can I send data on a separate thread than receive?

The docs for std.socket say nothing of it (which I guess means 
I should assume it is not thread safe but...).


Thanks!


Define thread safe.

It's safe in the way that the buffers each call to send will 
have will be what you expect.


Ex.

thread1 sends [1,2,3] and thread2 sends [4,5,6]

then you're guaranteed that what you receive would be [1,2,3] 
and [4,5,6].


What it isn't safe from would be race conditions.

So you don't know if you get it like [1,2,3,4,5,6] or 
[4,5,6,1,2,3].


So if the order of the buffer matters then you should use a 
mutex, but if the order doesn't matter then you don't need to.


You answered what I needed.

The order of receiving the messages is not a problem, merely that 
a message its self is not broken, ie: [4,1,2,5,3,6](This would 
not work!)


Thanks!


Is socket.send thread safe?

2018-03-26 Thread Jonathan via Digitalmars-d-learn
Can I send data over an std.socket on multiple threads without 
manual mutexing?


If not, can I send data on a separate thread than receive?

The docs for std.socket say nothing of it (which I guess means I 
should assume it is not thread safe but...).


Thanks!


Re: Can't add ubytes together to make a ubyte... bug or feature?

2018-03-17 Thread Jonathan via Digitalmars-d-learn

On Tuesday, 19 January 2016 at 23:36:14 UTC, Adam D. Ruppe wrote:
On Tuesday, 19 January 2016 at 22:12:06 UTC, Soviet Friend 
wrote:
I don't care if my computer needs to do math on a 4 byte 
basis, I'm not writing assembly.


x86 actually doesn't need to do math that way, if you were 
writing assembly, it would just work. This is just an annoying 
rule brought over by C.



Can I prevent the initial implicit casts?


Nope, though you can help tell the compiler that you want it to 
fit there by doing stuff like


ubyte a = 200;
ubyte b = 100;
ubyte c = (a+b)&0xff;

or something like that, so the expression is specifically 
proven to fit in the byte with compile time facts.



`(a+b)&0xff` What is this syntax?!  Could you give a link to this 
in the D documentation?  I am not even sure how to look it up...


Inline Module / Namespace

2018-03-09 Thread Jonathan via Digitalmars-d
D kinda lacks a way of creating a module/namespace inside another 
file.


D does have modules but they have to be in separate files.  
(Though separate files may be better coding practice, why is it 
D's job to tell me how to code.)


I think a simple way to do this with existing syntax is to add 
functionality for `module` to be used as a block.



module modulename {
void fun(){}
}
modulename.fun();


An inline module.


Re: Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]

2018-02-27 Thread Jonathan via Digitalmars-d-learn

On Tuesday, 27 February 2018 at 22:13:05 UTC, Jonathan wrote:
Is it possible to cast a 2d static length array to a 1d static 
length array?


E.g.
int[2][2] a = [[1,2],[3,4]];
int[4]b = cast(int[4])a;

Is not the byte data in memory exactly the same?


*( [pos,size].ptr .cst!(void*) .cst!(int[4]*) )
(using dub `cst` library) or
*( cast(int[4]*)(cast(void*)([pos,size].ptr)) )

Okay, this works but is this the best way?!


Cast a 2d static array to a 1d static array. T[s][r] -> T[s*r]

2018-02-27 Thread Jonathan via Digitalmars-d-learn
Is it possible to cast a 2d static length array to a 1d static 
length array?


E.g.
int[2][2] a = [[1,2],[3,4]];
int[4]b = cast(int[4])a;

Is not the byte data in memory exactly the same?


Re: Equivalent to Python with Statement

2018-02-27 Thread Jonathan via Digitalmars-d-learn

On Tuesday, 27 February 2018 at 16:18:43 UTC, Stefan Koch wrote:

On Tuesday, 27 February 2018 at 16:17:20 UTC, Jonathan wrote:
I know Python's `with` statement can be used to have an 
automatic close action:

```
with open("x.txt") as file:
#do something with file
#`file.close()` called automatically
```

I know D's `with` statement does something different but is 
there some sort of equivalent?


In this case with(File("bla"))
will do the same.


Oh really, cool.

Is this just because the scope of the file variable will end and 
thus its `~this`?




Equivalent to Python with Statement

2018-02-27 Thread Jonathan via Digitalmars-d-learn
I know Python's `with` statement can be used to have an automatic 
close action:

```
with open("x.txt") as file:
#do something with file
#`file.close()` called automatically
```

I know D's `with` statement does something different but is there 
some sort of equivalent?


Re: Template Constraints

2018-02-24 Thread Jonathan via Digitalmars-d-learn
On Saturday, 24 February 2018 at 03:04:07 UTC, Adam D. Ruppe 
wrote:

On Saturday, 24 February 2018 at 02:54:13 UTC, Jonathan wrote:
I am having trouble finding many useful explanations of using 
template constraints beyond basic usage.


The constraint is just like static if as to what it allows 
inside, so you can check almost anything in there.


Like for the cast, you might do

void name(T)(T t) if(__traits(compiles, cast(int) t) {}

just seeing it the cast compiles.

You might also do

if(is(T : int))

which asks if T is implicitly convertible to int. But since you 
want explicit cast, the compiles is prolly the way to go.


is: https://dlang.org/spec/expression.html#IsExpression
compiles: https://dlang.org/spec/traits.html#compiles


Thanks, this was just what I needed to know.


Template Constraints

2018-02-23 Thread Jonathan via Digitalmars-d-learn
I am having trouble finding many useful explanations of using 
template constraints beyond basic usage.


I would like to have a template constrant to enforce that a type 
can be explicitly cast to another type:


void (T)(T t)
if (cast(int) T)//force `cast(int) T` to be possible
{
// Yay I know `t` can be cast to an `int`!
}

Is this possible?


Implicit Casting

2018-02-06 Thread Jonathan via Digitalmars-d-learn
I am trying to make a `Pos` type.  But I need it to implicitly 
cast from an `int[2]`.
I am using the `alias this` to get most of what I want but it 
still doesn't do all an implicit cast can do.


What I have now is this:

struct Pos {
int[2] pos;
alias pos this;

this (int[2] pos) {
this.pos = pos;
}
}

This allows me to implicitly cast from type `Pos` to type 
`int[2]` but not the other way.  I can do a sort of cast when I 
define a `Pos` (`Pos pos = [2,3]` works).


But what I really want it to do is to implicitly cast an `int[2]` 
to a `Pos`.


Is this possible in D?


Re: Static if to compare two types are the exact same

2015-04-07 Thread Jonathan via Digitalmars-d-learn

static if (is(T == V))


Are static ifs always checked outside of runtime? Is it possible 
for a static if condition to be undeterminable outside of 
runtime, or would such a condition throw a compiler error?







Static if to compare two types are the exact same

2015-04-06 Thread Jonathan via Digitalmars-d-learn
What's the best way to do this? I'm assuming this should be best 
practice:

http://dlang.org/traits.html#isSame

struct S { }
writeln(__traits(isSame, S, S));


Re: Benchmark block

2015-03-31 Thread Jonathan via Digitalmars-d

@kind(benchmark) unittest


Is this possible currently?


Re: Benchmark block

2015-03-31 Thread Jonathan via Digitalmars-d

Would this do what you're after?

version(benchmark) {
unittest {
  import std.conv : to;
  int a;
  void f() {auto b = to!string(a);}
  auto r = benchmark!(f)(10_000);
  auto f0Result = to!Duration(r[0]);
  writeln(f0Result)
 }
}

rdmd -main -- -version=benchmark -unittest myapp.d


Well, I don't consider benchmarks a kind of unit test. So maybe 
just this:


version(benchmark) {
  import std.conv : to;
  int a;
  void f() {auto b = to!string(a);}
  auto r = benchmark!(f)(10_000);
  auto f0Result = to!Duration(r[0]);
  writeln(f0Result)
}

rdmd -main -- -version=benchmark myapp.d



Re: Easy bugs

2015-03-30 Thread Jonathan via Digitalmars-d
Actually, this is a good alternative: post here if anyone knows 
about simple bugs that I can tackle.


Although Martin, I wouldn't considering writing patches involving 
atomic ops to be easy/simple bugs. However, I think I know enough 
x86 asm to write an optimized version of atomicInc and atomicDec. 
I'll take a crack at it this week!



I'll start with a bunch of core.atomic improvements.

https://issues.dlang.org/show_bug.cgi?id=12891 - add atomicInc 
and

atomicDec to core.atomic
https://issues.dlang.org/show_bug.cgi?id=14117 - core.atomic 
should be @safe


That one is a bit harder, because it involves dmd and druntime, 
but it's

a huge improvement, implementation help guaranteed.

https://issues.dlang.org/show_bug.cgi?id=13713 - core.atomic 
should use

compiler intrinsics

-Martin




Unit testing druntime

2015-03-30 Thread Jonathan via Digitalmars-d
I noticed that I'm not able to unit test a file in isolation in 
druntime like I can in phobos. For example, I can't seem to run 
unit tests using the below method:

rdmd -unittest -main src/core/atomic.d

Is there a way to test modules in druntime like this?


Benchmark block

2015-03-30 Thread Jonathan via Digitalmars-d
I have no idea if this has been discussed yet, but I was thinking 
it would be neat to have benchmark blocks that only run when 
specified, like how unittest works.


Code:

benchmarks
{
 import std.conv : to;
 int a;
 void f() {auto b = to!string(a);}
 auto r = benchmark!(f)(10_000);
 auto f0Result = to!Duration(r[0]);
 writeln(f0Result)
}

Example:
rdmd -benchmarks -main myapp.d

Alternatively, the writeln could be replaced with some kind of 
standard benchmark output utility (similar to the idea of assert 
when used for unit tests).


Thoughts?


Re: The D Language: A sweet-spot between Python and C

2015-03-29 Thread Jonathan via Digitalmars-d
The syntax was a big part of D that got me hooked. It just 
feels right, as Python syntax often does, but with D there's 
raw power behind it.


I once wrote a few programs using a made up language to dream of 
my ideal language: D is the closest language that fits the bill. 
The constructs had language level support of ranges, function 
scope level imports, pure keyword, unified function call, and 
string mixins. The only thing missing honestly is proper support 
for ADTs/Enum-types (with enforcing an exhaustive match when 
switch/casing).





Easy bugs

2015-03-29 Thread Jonathan via Digitalmars-d

Hey folks,

I'm been starting to work on Debian bugs and found that most of 
the issues are eventually ranked from easy to hard to fix. I 
wondering if we can do the same (if not already). I think it 
would encourage new folks to pick up tasks (like myself).


Best D pitch

2015-03-25 Thread Jonathan via Digitalmars-d

Hey folks,

What's the best article/resource that I could give to a C++/C# 
developer to convince them on D? Ideally, I'm looking for 
something concise on the benefits with several examples.


Re: Best D pitch

2015-03-25 Thread Jonathan via Digitalmars-d
Thanks Joakim! That's a great article, I've remember reading it 
years ago that originally attracted me to the language. I was 
hoping for something more concise: perhaps a single page with 
language highlights.




Re: Release D 2.067.0

2015-03-24 Thread Jonathan via Digitalmars-d-announce
Thanks to everyone who helped make this happen! This release 
sounds like a solid milestone in multiple crucial areas.


Here's to the next release!


Re: D and Nim

2015-01-05 Thread Jonathan via Digitalmars-d
Thanks everyone for the incite so far! Reading between the lines, 
I gather most thoughts are that both languages are similar in 
their positioning/objectives yet differ in certain domains (e.g. 
generic/template capabilities) and qualities (e.g. Nim 
opinionated choice of scope delimiters). Does that sound logical? 
This was kind of the thing I was fishing for when thinking of the 
post.


D and Nim

2015-01-04 Thread Jonathan via Digitalmars-d

Hey folks,

I've been recently checking out Nim/rod and feel like it takes a 
lot of inspiration from D (I think the creator was in the D 
community too as some point). How do you think it compares? What 
areas does D, in principle, makes it a better choice? To give you 
my background, I like creating games (mostly using SDL bindings) 
using new languages, aiming for the most efficient yet concise 
way to write the engine and game logic.


FYI, this is NOT a language war thread. I'm just curious about 
what separates them from a principle level.


Re: D and Nim

2015-01-04 Thread Jonathan via Digitalmars-d
I will say that Nim's documentation is severely lacking, even 
compared to D. For example, it took me far more time figuring out 
Nim's file io operations.


Re: D and Nim

2015-01-04 Thread Jonathan via Digitalmars-d
On a subjective note, I've always felt that D gets me as a 
developer. This is extremely subjective, but I found that in many 
cases I could just write code without consulting documentation 
when I was learning the language. Even talking about the 
immutable For statement, I discovered this by writing code that 
seemed logical to the situation.


Re: D Meetup in SF?

2014-12-05 Thread Jonathan via Digitalmars-d
I'm also down for a SF meetup. TBH, I haven't written much D 
lately (game developer), but I'd love to participate.


Re: Do everything in Java…

2014-12-05 Thread Jonathan via Digitalmars-d
JEE is the evolution of distributed CORBA applications in the 
enterprise, with .NET enterprise applications being the 
evolution of DCOM.


Both games that C++ lost its place at.


What about zeromq with C++ or even resorting to simple internal 
REST protocols. I've yet to see a valid argument that DCOM (not 
sure about COBRA) offer a tangible benefit over simpler 
approaches. Thoughts?




Re: What are the worst parts of D?

2014-10-08 Thread Jonathan via Digitalmars-d

My small list of D critiques/wishes from a pragmatic stance:

1) Replace the Stop the World GC
2) It would be great if dmd could provide a code-hinting 
facility, instead of relying on DCD which continually breaks for 
me. It would open more doors for editors to support better code 
completion.
3) Taking a hint from the early success of Flash, add Derelict3 
(or some basic OpenGL library) directly into Phobos. Despite some 
of the negatives (slower update cycle versus external lib), it 
would greatly add to D's attractiveness for new developers. I 
nearly left D after having a host issues putting Derelict3 into 
my project. If I had this issue, we may be missing out from 
attracting newbies looking to do gfx related work.


I'm sure this has been talked about, but I'll bring it up anyway:
To focus our efforts, consider switching to ldc. Is it worth 
people's time to continue to optimize DMD when we can accelerate 
our own efforts by relying on an existing compiler? As some have 
pointed out, our community is spread thin over so many efforts... 
perhaps there are ways to consolidate that.


Just my 2cents from a D hobbyist..


Re: The pull request of the day: 3998

2014-10-07 Thread Jonathan via Digitalmars-d
What are some common uses for multiple aliasing? I understand 
the feature, but curious where it would be commonly employed.


To me, this allows structs to have something like inheritance. 
You add a property for another struct that acts like an interface 
and alias that struct to the current one. Thoughts?


GC behavior

2014-10-06 Thread Jonathan via Digitalmars-d
If I pool all unused objects such that no object needs to be 
GC'ed, does it still perform scanning? What are other good ways 
to avoid its overhead? As you might tell, I know rather little 
how D's garbage collection works. I'm working on a game engine 
and trying to be as resource efficient as possible.


FYI, I've been using Rust for the last three months and decided 
to take a break from it. The documentation is far from the 
quality that D has and managing explicit lifetimes becomes a 
serious pain during mid project, especially in cases that you 
know are already safe.


Re: Algebraic data types

2014-10-06 Thread Jonathan via Digitalmars-d

Resurrecting this topic, does D have ADTs yet for enums/structs?


Re: Algebraic data types

2014-10-06 Thread Jonathan via Digitalmars-d

NM, I found this:
http://www.digitalmars.com/d/archives/digitalmars/D/Algebraic_Data_Types_in_D_239039.html

D's Algebraic needs some work, but it's okay for basic usage. 
+1 agree



import std.stdio;
import std.variant;

struct Red {}
struct Green{}
struct Blue {}
struct RGB
{
int r;
int g;
int b;
}

alias Color = Algebraic!(Red, Green, Blue, RGB);

void main()
{
auto r = Color(RGB(64, 128, 255));
r.visit!(
(Red   r) = writeln(Red),
(Green g) = writeln(Green),
(Blue  b) = writeln(Blue),
(RGB rgb) = writefln(RGB(%s, %s, %s), rgb.r, rgb.g, rgb.b),
);
}


Re: GC behavior

2014-10-06 Thread Jonathan via Digitalmars-d
Kiith-Sa, thanks for the info! I started to check out your entity 
project and love how your incorporating threads and syncing 
new/old state. You did state that your cleaning up things, but my 
initial reaction is that entitymanager is performing too many 
roles. I'd remove the heavy game state and threading into another 
class to make it cleaner, imho.


https://github.com/kiith-sa/tharsis-core/blob/master/source/tharsis/entity/entitymanager.d


switch statement exiting a void function

2014-09-16 Thread Jonathan via Digitalmars-d-learn

Here's the setup, I have a function

void main { ... }

The main method parses input (via std.getopt) and calls one of 
three void-return-type functions.  The program's three options 
correspond to significantly different initialization options.


In the code we then have:

enum RunOpt {opt1, opt2, opt3};

And the body of the function wants to do:

RunOpt option;
//parsing that results in, among other things option being 
initialized

switch(option){
case RunOpt.opt1: fun1(...);
case RunOpt.opt2: fun2(...);
default: fun3(...);
}

When compiling, the error I get is

Error: switch case fallthrough - use 'goto case;' if intended

This is not intended.  Note that calling return; after 
funi(...) makes everything work.  However, it feels like I'm 
doing something wrong here?


Re: switch statement exiting a void function

2014-09-16 Thread Jonathan via Digitalmars-d-learn

Try:

enum RunOpt { opt1, opt2, opt3 } // No semicolon here

final switch (option) with (RunOpt) {
case opt1: fun1(...); break;
case opt2: fun2(...); break;
case opt3: fun3(...); break;
}

Bye,
bearophile


My hero.