D and memory mapped devices

2017-06-14 Thread Russel Winder via Digitalmars-d-learn
In C and C++ you often use bitfields to control devices with memory mapped hardware control and data words. So for example: typedef struct some_device { unsigned int flob: 3; unsigned int adob: 2; unsigned int: 3; unsigned int data: 8; } some_device; Clearly D has no bitfields. I

Re: D and memory mapped devices

2017-06-14 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 08:10:57 UTC, Russel Winder wrote: but the bitfields mixin template appears to do more than add all the bit twiddling functions to emulate the bitfields. This would appear a priori to not allow for actual memory mapped devices using it, or am I missing something?

Re: Generic operator overloading for immutable types?

2017-06-14 Thread ag0aep6g via Digitalmars-d-learn
On 06/14/2017 03:47 AM, Steven Schveighoffer wrote: The fundamental difference is that const and immutable share a characteristic that mutable doesn't -- you can't mutate the data. (... through the reference at hand.) const and mutable share this: The data may be mutated from elsewhere. Mutab

Implementing interfaces using alias this

2017-06-14 Thread Balagopal Komarath via Digitalmars-d-learn
Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. import std.stdio; interface IDuck { void quack(); } class Test(T) : IDuck { T data; alias data this; } struct Duck { void quack() { writeln("Quack");

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. 'cause `alias this` is *not* a tool that can be used to emulate inheritance. no, `quack` is NOT impemented. `alias this` won't automagically paste the co

is it bug? (out contract in method causes dmd (2.072.2, 2.74.1) segfaults)

2017-06-14 Thread drug via Digitalmars-d-learn
https://dpaste.dzfl.pl/b66fffa3bc8d

Re: is it bug? (out contract in method causes dmd (2.072.2, 2.74.1) segfaults)

2017-06-14 Thread ag0aep6g via Digitalmars-d-learn
On 06/14/2017 01:06 PM, drug wrote: https://dpaste.dzfl.pl/b66fffa3bc8d It's always a bug when dmd segfaults.

Re: Implementing interfaces using alias this

2017-06-14 Thread Balagopal Komarath via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 09:41:49 UTC, ketmar wrote: Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. 'cause `alias this` is *not* a tool that can be used to emulate inheritance. no, `quack` is NOT

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Balagopal Komarath wrote: On Wednesday, 14 June 2017 at 09:41:49 UTC, ketmar wrote: Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. 'cause `alias this` is *not* a tool that can be used to emulate inh

Re: is it bug? (out contract in method causes dmd (2.072.2, 2.74.1) segfaults)

2017-06-14 Thread drug via Digitalmars-d-learn
14.06.2017 14:25, ag0aep6g пишет: It's always a bug when dmd segfaults. filed https://issues.dlang.org/show_bug.cgi?id=17502

Re: Generic operator overloading for immutable types?

2017-06-14 Thread Kagamin via Digitalmars-d-learn
On Tuesday, 13 June 2017 at 19:29:26 UTC, Gary Willoughby wrote: Is it possible for the `result` variable in the following code to be returned as an immutable type if it's created by adding two immutable types? Why do you even want that? Such plain data structure is implicitly convertible to

Re: Implementing interfaces using alias this

2017-06-14 Thread Mike B Johnson via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 09:41:49 UTC, ketmar wrote: Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. 'cause `alias this` is *not* a tool that can be used to emulate inheritance. no, `quack` is NOT

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Mike B Johnson wrote: I don't think it has to do with pasting code. d.Quack() is well defined through the alias. Inheritance requires that a Quack() exists, and it does, through the alias. The compiler could easily create an implementation wrapper that uses the alias this. this is called

Re: Implementing interfaces using alias this

2017-06-14 Thread Balagopal Komarath via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 11:40:02 UTC, ketmar wrote: interfaces *require* a full-featured class, with VMT, and some hidden pointers to support hidden interface machinery. I don't think that is the problem here. The type Test!Duck is a class and that type is the one implementing the interf

Re: Implementing interfaces using alias this

2017-06-14 Thread Balagopal Komarath via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 12:35:05 UTC, Mike B Johnson wrote: void main() { Test!Duck d; d.quack(); } which, unfortunately causes a segmentation fault ;) I think that is because you are not initializing d using new Test!Duck();

Re: D and memory mapped devices

2017-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/17 4:10 AM, Russel Winder via Digitalmars-d-learn wrote: In C and C++ you often use bitfields to control devices with memory mapped hardware control and data words. So for example: typedef struct some_device { unsigned int flob: 3; unsigned int adob: 2; unsigned int: 3; u

Re: Implementing interfaces using alias this

2017-06-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/14/17 5:34 AM, Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. import std.stdio; interface IDuck { void quack(); } class Test(T) : IDuck { T data; alias data this; } struct Duck { v

Re: D and memory mapped devices

2017-06-14 Thread Vladimir Panteleev via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 08:10:57 UTC, Russel Winder wrote: This would appear a priori to not allow for actual memory mapped devices using it, or am I missing something? I believe the only case where it might matter is if the device was sensitive to the read/write size (1/2/4 bytes). Othe

Re: D and memory mapped devices

2017-06-14 Thread Jacob Carlborg via Digitalmars-d-learn
On 2017-06-14 11:04, Rene Zwanenburg wrote: I've casted void buffers to structs containing bitfields to read pre-existing binary files, and that worked just fine. I don't see why it would be different for memory mapped devices. What do yo mean by 'do more'? This bitfield discussion came up in

Re: Implementing interfaces using alias this

2017-06-14 Thread ketmar via Digitalmars-d-learn
Balagopal Komarath wrote: On Wednesday, 14 June 2017 at 11:40:02 UTC, ketmar wrote: interfaces *require* a full-featured class, with VMT, and some hidden pointers to support hidden interface machinery. I don't think that is the problem here. The type Test!Duck is a class and that type is the

Re: Implementing interfaces using alias this

2017-06-14 Thread basile b. via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 09:34:27 UTC, Balagopal Komarath wrote: Why doesn't this work? The Test!Duck type has a void quack() method but the compiler says it is not implemented. import std.stdio; interface IDuck { void quack(); } class Test(T) : IDuck { T data; alias data thi

Builtin array-scalar equality

2017-06-14 Thread Nordlöw via Digitalmars-d-learn
Why isn't bool c = a[] == 4; allowed when a[] = b[] + 4; is? given that int[] a, b;

Re: Builtin array-scalar equality

2017-06-14 Thread Meta via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 21:15:32 UTC, Nordlöw wrote: Why isn't bool c = a[] == 4; allowed when a[] = b[] + 4; is? given that int[] a, b; That's just how it is. There are a lot of array-wise operations that *could* be implemented in the language but aren't.

Re: Implementing interfaces using alias this

2017-06-14 Thread Balagopal Komarath via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 21:04:55 UTC, basile b. wrote: The way to do that in D is with mixins: That is an interesting solution. However, my original goal was to figure out whether one can make struct types behave polymorphically (Which is not mentioned in my original question). I know

Re: Implementing interfaces using alias this

2017-06-14 Thread basile b. via Digitalmars-d-learn
On Wednesday, 14 June 2017 at 22:29:08 UTC, Balagopal Komarath wrote: On Wednesday, 14 June 2017 at 21:04:55 UTC, basile b. wrote: The way to do that in D is with mixins: That is an interesting solution. However, my original goal was to figure out whether one can make struct types behave pol

Help with an algorithm!

2017-06-14 Thread MGW via Digitalmars-d-learn
There are two arrays of string [] mas1, mas2; Size of each about 5M lines. By the size they different, but lines in both match for 95%. It is necessary to find all lines in an array of mas2 which differ from mas1. The principal criterion - speed. There are the 8th core processor and it is good