Float values are wrong in union

2016-08-21 Thread stunaep via Digitalmars-d-learn
I made a union to convert between int bits and floats, but the values are coming out wrong sometimes. This is working without issue in other languages so I'm really stumped. Here's an example: union test { int i; float f; } test t = { i : 0x7fb0}; float t2 = t.f;//int bits 0x7fb0 as

Re: Variant and immutable struct

2016-08-21 Thread Øivind via Digitalmars-d-learn
On Sunday, 10 January 2016 at 17:50:44 UTC, Vlad Leberstein wrote: As I'm not very good at D, I would like to get some feedback about this solutions' viability. AFAIU memcpy-ing struct here is safe because all target arguments ever passed to tryPutting are internal to implementation(and

Re: Is there a d analog of strncmp?

2016-08-21 Thread dan via Digitalmars-d-learn
On Monday, 22 August 2016 at 01:45:02 UTC, Jonathan M Davis wrote: On Monday, August 22, 2016 00:14:31 Adam D. Ruppe via Digitalmars-d-learn wrote: int strncmp(string a, string b, int n) { if(a.length > n) a = a[0 .. n]; if(b.length > n) b = b[0 .. n]; import

Re: Float values are wrong in union

2016-08-21 Thread jkpl via Digitalmars-d-learn
On Monday, 22 August 2016 at 04:37:50 UTC, stunaep wrote: I made a union to convert between int bits and floats, but the values are coming out wrong sometimes. This is working without issue in other languages so I'm really stumped. Here's an example: union test { int i; float f; } test t =

Re: Float values are wrong in union

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Monday, 22 August 2016 at 04:37:50 UTC, stunaep wrote: I made a union to convert between int bits and floats, but the values are coming out wrong sometimes. I can already tell what this is going to be... The problem is almost certainly nothing to do with your union, it's this line: float

Re: Float values are wrong in union

2016-08-21 Thread jkpl via Digitalmars-d-learn
On Monday, 22 August 2016 at 04:52:40 UTC, Cauterite wrote: On Monday, 22 August 2016 at 04:37:50 UTC, stunaep wrote: I made a union to convert between int bits and floats, but the values are coming out wrong sometimes. I can already tell what this is going to be... The problem is almost

Re: DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?

2016-08-21 Thread Sai via Digitalmars-d-learn
Thanks all for your replies. I tried to use GDC first, I couldn't find windows binary targeting windows (for initial testing) which I thought was weird. https://gdcproject.org/downloads So I tried to build it in Cygwin env, using these instructions:

Re: DMD on ARM/Linux (for controlling EV3 Lego Mindstorm)?

2016-08-21 Thread rikki cattermole via Digitalmars-d-learn
On 22/08/2016 5:22 PM, Sai wrote: Thanks all for your replies. I tried to use GDC first, I couldn't find windows binary targeting windows (for initial testing) which I thought was weird. https://gdcproject.org/downloads So I tried to build it in Cygwin env, using these instructions:

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 1) If using the GC, but for whatever reason, I need to free something _right now_, is core.GC.free() the proper way to do this? The main problem is that `new` does not necessarily give you a pointer to the start of an allocation, and

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 18:31:26 UTC, Zane wrote: I see - That makes sense, but is there no way to "pause/stop" the GC, but still be able to use the 'new' syntax? Oh you can use `new` when the GC is disabled, no problem. All the GC's functionality is still available. But be careful

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 21 August 2016 at 06:28:25 UTC, Jack Applegame wrote: On Sunday, 21 August 2016 at 00:06:07 UTC, Engine Machine wrote: On Saturday, 20 August 2016 at 22:21:00 UTC, ag0aep6g wrote: On 08/21/2016 12:11 AM, Engine Machine wrote: Is there a way to rebind the arguments of a template?

Re: Sequence separation

2016-08-21 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Wednesday, 17 August 2016 at 19:38:22 UTC, Engine Machine wrote: Well, the is does work and that probably is the best solution. I don't mind the extra type at this point. Of course, a library solution for this type of stuff would be nice. I'd rather not have to even use a type but rather

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 5) Is there a way to do simple heap allocation with 'new' while ensuring the GC doesn't deallocate until I want it to? While my earlier suggestion of using malloc/emplace is one option, another is to use `GC.addRoot(objPtr)`. It ensures

Re: Thread affinity?

2016-08-21 Thread cpupinner via Digitalmars-d-learn
On Wednesday, 4 December 2013 at 23:23:51 UTC, Rob T wrote: On Wednesday, 4 December 2013 at 08:38:12 UTC, qznc wrote: You should file an issue [0] as this should actually be in core.thread. [0] https://d.puremagic.com/issues/enter_bug.cgi I filed an enhancement request for the thread

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Guillaume Piolat via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: Hey all, My knowledge of GCs is limited, but my faith in them (for most applications) has greatly increased with advances (like with Golang's recent updates). I am now trying to get a better sense for the direction D is going regarding

Re: Rebind template(bug?)

2016-08-21 Thread Jack Applegame via Digitalmars-d-learn
On Sunday, 21 August 2016 at 19:29:26 UTC, Engine Machine wrote: I know you like to play the right or wrong game, but did you ever learn that a single example does not prove the truth of something? How about something more complex? Your demagogy will not help you learn the basics of the D

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 5) Is there a way to do simple heap allocation with 'new' while ensuring the GC doesn't deallocate until I want it to? I can answer this at least, If you don't want the GC to ever collect the object itself, here's the best way: Allocate

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Zane via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:38:09 UTC, Cauterite wrote: On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 5) Is there a way to do simple heap allocation with 'new' while ensuring the GC doesn't deallocate until I want it to? I can answer this at least, If you don't want the GC to

Re: Rebind template

2016-08-21 Thread Alexandru Ermicioi via Digitalmars-d-learn
On Saturday, 20 August 2016 at 22:18:57 UTC, Engine Machine wrote: On Saturday, 20 August 2016 at 22:11:40 UTC, Engine Machine wrote: Is there a way to rebind the arguments of a template? template foo(X) { // X is like A!(a,b,c) Y = Rebind!(X,d,e,f); // Y is like A!(d,e,f); }

Re: Rebind template(bug?)

2016-08-21 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 21 August 2016 at 20:36:54 UTC, Engine Machine wrote: On Sunday, 21 August 2016 at 19:42:08 UTC, Lodovico Giaretta wrote: [...] You're right. I didn't realize that variables could be shadowed in classes. Seems dangerous. D doesn't allow shadowing in a normal context and gives an

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 2) Does calling object.destroy() mean that the object is marked for future collection? If not, how can I ensure it is properly marked. Because the GC is not of the incremental type, it can't perform any marking outside of a

Re: Rebind template(bug?)

2016-08-21 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 21 August 2016 at 19:42:08 UTC, Lodovico Giaretta wrote: On Sunday, 21 August 2016 at 19:29:26 UTC, Engine Machine wrote: [...] The problem of this code has nothing to do with aliases. They work correctly. The problem is variable shadowing. In the following code, Child has two x

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 21 August 2016 at 19:42:08 UTC, Lodovico Giaretta wrote: On Sunday, 21 August 2016 at 19:29:26 UTC, Engine Machine wrote: [...] The problem of this code has nothing to do with aliases. They work correctly. The problem is variable shadowing. In the following code, Child has two x

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Cauterite via Digitalmars-d-learn
On Sunday, 21 August 2016 at 16:14:53 UTC, Zane wrote: 6) If the GC is off, how is allocation/deallocation handled? Can I still use new for example (and how do I dealloc)? All the allocation/deallocation functionality is the same as normal, except the GC won't start a collection cycle unless

Re: Rebind template(bug?)

2016-08-21 Thread Lodovico Giaretta via Digitalmars-d-learn
On Sunday, 21 August 2016 at 19:29:26 UTC, Engine Machine wrote: [...] The problem of this code has nothing to do with aliases. They work correctly. The problem is variable shadowing. In the following code, Child has two x variables, one of which is only accessible from a Parent reference,

Re: Mem Mgmt: With & Without the GC

2016-08-21 Thread Zane via Digitalmars-d-learn
Thanks to both of you. I think that answers everything, except if new'd objects can be freed when GC is disabled. I guess I could always enable and call collect().

How to avoid ctRegex (solved)

2016-08-21 Thread cy via Digitalmars-d-learn
At seconds PER (character range) pattern, ctRegex slows down compilation like crazy, but it's not obvious how to avoid using it, since Regex(Char) is kind of weird for a type. So, here's what I do. I think this is right. in the module scope, you start with: auto pattern = ctRegex!"foobar";

Re: Rebind template(bug?)

2016-08-21 Thread ag0aep6g via Digitalmars-d-learn
On 08/21/2016 09:29 PM, Engine Machine wrote: I know you like to play the right or wrong game, but did you ever learn that a single example does not prove the truth of something? But you can show in a single example that something doesn't work. You tried to do that, and you did it with a

Is there a d analog of strncmp?

2016-08-21 Thread dan via Digitalmars-d-learn
In c, there's this very nice function strncmp(s1,s2,count) which compares two c strings, using at most count characters. count can be less than, more than, or equal to either or both of the lengths of the two strings. It can be used to see if two c-strings have the same prefix of some

Re: Creating an array of user-defined structs

2016-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 August 2016 at 23:57:27 UTC, brian wrote: I understand it's a map, but does my syntax not define an Associative Array?? yeah, it is. If that's what you want, good! So I wanted something dynamic. OK, then you should use pointers so you can have several references to the same

Re: Is there a d analog of strncmp?

2016-08-21 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, August 22, 2016 00:14:31 Adam D. Ruppe via Digitalmars-d-learn wrote: > int strncmp(string a, string b, int n) { > if(a.length > n) > a = a[0 .. n]; > if(b.length > n) > b = b[0 .. n]; > import std.algorithm.comparison : cmp; > return cmp(a, b); > } Aside from the

Re: Is there a d analog of strncmp?

2016-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
int strncmp(string a, string b, int n) { if(a.length > n) a = a[0 .. n]; if(b.length > n) b = b[0 .. n]; import std.algorithm.comparison : cmp; return cmp(a, b); }

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Sunday, 21 August 2016 at 21:11:37 UTC, ag0aep6g wrote: On 08/21/2016 09:29 PM, Engine Machine wrote: I know you like to play the right or wrong game, but did you ever learn that a single example does not prove the truth of something? But you can show in a single example that something

Re: Creating an array of user-defined structs

2016-08-21 Thread Adam D. Ruppe via Digitalmars-d-learn
On Sunday, 21 August 2016 at 23:28:14 UTC, brian wrote: /* creates(?) an empty array of structs */ testStruct[int] testStructArray; That's not actually an array per se, that is a key/value map where the keys are ints. So you can set values to it at any position in it but not append or do

Re: Creating an array of user-defined structs

2016-08-21 Thread brian via Digitalmars-d-learn
Thanks Adam. Couple of follow up questions, if you don't mind: On Sunday, 21 August 2016 at 23:37:38 UTC, Adam D. Ruppe wrote: testStruct[int] testStructArray; That's not actually an array per se, that is a key/value map where the keys are ints. I understand it's a map, but does my syntax not

Re: Rebind template(bug?)

2016-08-21 Thread ag0aep6g via Digitalmars-d-learn
On 08/22/2016 12:06 AM, Engine Machine wrote: T!()'s "data" is specified in the class just like all the other derivations. I don't want to have to specify an external base class as in your InstaniateOrBase. Why? Because!!! (There should be no need to, and if one goes this route of creating

Re: Rebind template(bug?)

2016-08-21 Thread Engine Machine via Digitalmars-d-learn
On Monday, 22 August 2016 at 00:22:48 UTC, ag0aep6g wrote: On 08/22/2016 12:06 AM, Engine Machine wrote: T!()'s "data" is specified in the class just like all the other derivations. I don't want to have to specify an external base class as in your InstaniateOrBase. Why? Because!!! (There

Is it's possible to install DMD/LDC/GDC on CoreOS?

2016-08-21 Thread Suliman via Digitalmars-d-learn
I would like to create small VPS instance with Linux distrib on VPS. Can I use CoreOS as image? Would it possible to install dlang there?

Re: Rebind template

2016-08-21 Thread Jack Applegame via Digitalmars-d-learn
On Sunday, 21 August 2016 at 00:06:07 UTC, Engine Machine wrote: On Saturday, 20 August 2016 at 22:21:00 UTC, ag0aep6g wrote: On 08/21/2016 12:11 AM, Engine Machine wrote: Is there a way to rebind the arguments of a template? template foo(X) { // X is like A!(a,b,c) Y =

Re: Is it's possible to install DMD/LDC/GDC on CoreOS?

2016-08-21 Thread David Nadlinger via Digitalmars-d-learn
On Sunday, 21 August 2016 at 11:38:09 UTC, Suliman wrote: I would like to create small VPS instance with Linux distrib on VPS. Can I use CoreOS as image? Would it possible to install dlang there? For LDC, you can just download the latest release from

Re: Is it's possible to install DMD/LDC/GDC on CoreOS?

2016-08-21 Thread Seb via Digitalmars-d-learn
On Sunday, 21 August 2016 at 11:38:09 UTC, Suliman wrote: I would like to create small VPS instance with Linux distrib on VPS. Can I use CoreOS as image? Would it possible to install dlang there? An alternative would be to compile your application locally, then copy it over to your

Re: Is it's possible to install DMD/LDC/GDC on CoreOS?

2016-08-21 Thread David Nadlinger via Digitalmars-d-learn
On Sunday, 21 August 2016 at 14:57:15 UTC, Seb wrote: An alternative would be to compile your application locally, then copy it over to your container. I don't know how similar CoreOs to a typical Linux distribution is, but if it comes with the typical shared libraries (libm.so, libc.so,

Re: Is it's possible to install DMD/LDC/GDC on CoreOS?

2016-08-21 Thread Seb via Digitalmars-d-learn
On Sunday, 21 August 2016 at 15:25:59 UTC, David Nadlinger wrote: On Sunday, 21 August 2016 at 14:57:15 UTC, Seb wrote: An alternative would be to compile your application locally, then copy it over to your container. I don't know how similar CoreOs to a typical Linux distribution is, but if

Mem Mgmt: With & Without the GC

2016-08-21 Thread Zane via Digitalmars-d-learn
Hey all, My knowledge of GCs is limited, but my faith in them (for most applications) has greatly increased with advances (like with Golang's recent updates). I am now trying to get a better sense for the direction D is going regarding memory management, both in relation to the GC and