Re: Why does this not work?

2014-09-17 Thread Shachar via Digitalmars-d-learn
On Wednesday, 17 September 2014 at 13:03:05 UTC, flamencofantasy wrote: the result of ubyte + ubyte is int I believe. Try; void func( int c ) { ubyte a; a = cast(ubyte)(cast(ubyte)c + cast(ubyte)c); } From http://dlang.org/type, under Usual Arithmetic Conversions: 4. Else the intege

Why does this not work?

2014-09-17 Thread Shachar via Digitalmars-d-learn
void func( int c ) { ubyte a; a = cast(ubyte)c + cast(ubyte)c; } dmd v2.065 complains about: test.d(5): Error: cannot implicitly convert expression (cast(int)cast(ubyte)c + cast(int)cast(ubyte)c) of type int to ubyte As far as I can tell, adding two values of the same type should re

Why is this pure?

2014-08-24 Thread Shachar via Digitalmars-d-learn
The following program compiles, and does what you'd expect: struct A { int a; } pure int func( ref A a ) { return a.a += 3; } As far as I can tell, however, it shouldn't. I don't see how or why func can possibly be considered pure, as it changes a state external to the function. Wha

Re: onDispatch demo not compiling

2014-08-20 Thread Shachar via Digitalmars-d-learn
On Thursday, 21 August 2014 at 06:11:06 UTC, ketmar via Digitalmars-d-learn wrote: that will do the trick. Indeed. I ended up simply directly calling "a.opDispatch!"do_something_cool"(5, 6)", which brought most of those issues to light. Shachar

onDispatch demo not compiling

2014-08-20 Thread Shachar via Digitalmars-d-learn
I'm trying to compile the onDispatch demo program from "The D Programming Language" (page 387). At first I had an import problem, but I fixed that. Now, however, when I try to call "a.do_something_cool", I get an error message saying: onDispatch.d(43): Error: no property 'do_something_cool' fo