d

Does the D language have multiple standard libraries and issues with GC?

半城伤御伤魂 提交于 2019-12-20 09:56:15
问题 I'm wondering how mature and stable D is, and if it might be a good replacement for C/C++. I know that there are currently two standard libraries (Phobos and Tango). Is it still the case that there is no unified standard library? Additionally I heard some time ago that the languages has problems on the boundaries of GCed/non-GCed code. I couldn't find any reference about that on the D website, so is this problem still true? 回答1: Version 1 of D is mature and stable, and there are definitely

Turning off the D garbage collector

狂风中的少年 提交于 2019-12-20 08:36:47
问题 I'm a C++ programmer thats considering using D for a personal project I want to play around with. I was wondering if there's a way to completely disable the garbage collector, and what the risks are of doing so. I know I can manage my own memory by overriding new and delete to use malloc and free, but if I did that I'd rather the garbage collector not run at all. 回答1: To turn off the GC in D2: import core.memory; void main(string[] args) { GC.disable; // Do stuff. } If using D1/Phobos: import

Calling a D function directly from C++

一曲冷凌霜 提交于 2019-12-20 01:38:40
问题 I've gone through http://dlang.org/cpp_interface.html and in all of the examples, even those where some C++ code calls some D code, the main function resides in D (and so the binary being called is the one compiled from the D source file). The "calling D from C++" example in the doc has a function foo defined in D, which gets called from a function bar in C++, and bar in turn gets called from the main function in D. Is it possible to just call D code from the C++ function? I'm trying to do

Float literal and range parameter in ANTLR

陌路散爱 提交于 2019-12-20 01:15:06
问题 I'm working on a parser for the language D and I ran in to trouble when I tried to add the "slice" operator rule. You can find the ANTLR grammar for it here. Basically the problem is that if the lexer encounters a string like this: "1..2" it gets completely lost, and it ends up being as a single float value and therefore the postfixExpression rule for a string like "a[10..11]" ends up being a ExpArrIndex object with a ExpLiteralReal argument. Can somebody explain what is exactly wrong with

Difference between 'const ref' and 'in'?

谁都会走 提交于 2019-12-18 18:59:14
问题 I'm trying to understand the difference between const ref and in , specially when it comes to performance. I know that in is equivalent to const scope , but what does the scope stor­age class means that ref­er­ences in the pa­ra­me­ter can­not be es­caped (e.g. as­signed to a global vari­able). mean? example code is welcome. How do I decide between const ref and in when implementing a function? I know with ref the object doesn't get copied because it's a reference, but is the same true with

Difference between 'const ref' and 'in'?

故事扮演 提交于 2019-12-18 18:59:02
问题 I'm trying to understand the difference between const ref and in , specially when it comes to performance. I know that in is equivalent to const scope , but what does the scope stor­age class means that ref­er­ences in the pa­ra­me­ter can­not be es­caped (e.g. as­signed to a global vari­able). mean? example code is welcome. How do I decide between const ref and in when implementing a function? I know with ref the object doesn't get copied because it's a reference, but is the same true with

Should I use 'long' instead of 'int' on 64-bits in langs with fixed type size (like Java, C#)

耗尽温柔 提交于 2019-12-18 07:37:48
问题 In 10, or even 5 years there will be no [ Edit2: server or desktop] 32-bit CPUs. So, are there any advantages in using int (32bit) over long (64bit) ? And are there any disadvantages in using int ? Edit: By 10 or 5 years I meant on vast majority of places where those langs are used I meant which type to use by default . This days I won't even bother to think if I should use short as cycle counter, just for(int i... . The same way long counters already win registers are already 64-bit, there

What is the difference between const and immutable in D?

耗尽温柔 提交于 2019-12-18 02:00:08
问题 What is the difference between the const and immutable type qualifiers in D? 回答1: Something that is const cannot be mutated via that reference but could be mutated by a mutable reference to the same data. Something that is immutable can't be mutated by any reference to that data. So, if you have const C c = foo(); then you know that you cannot mutate the object referred to by c through c , but other references to the object referred to by c may exist in your code, and if they're mutable, they

Is multiplication always commutative in inexact floating point arithmetic?

 ̄綄美尐妖づ 提交于 2019-12-17 20:51:15
问题 I'm trying to understand some code in the D language runtime. It seems like there are separate functions for the following two things: array1[] += scalar * array2[]; array1[] += array2[] * scalar; Why can't these be done with one function? I thought multiplication was commutative even in inexact floating-point arithmetic. 回答1: I know nothing about the D language, but I'll happily answer the question in your title: Is multiplication always commutative in inexact floating point arithmetic? Up

Add package dependencies with Mono-d or Visual-d

落花浮王杯 提交于 2019-12-14 03:59:57
问题 With dub I can do this in the dub.json file: { "name": "myproject", "description": "A little web service of mine.", "authors": ["Peter Parker"], "homepage": "http://myproject.com", "license": "GPL-2.0", "dependencies": { "vibe-d": ">=0.7.11" } } What is the equivalent thing in Mono-D or Visual-D? 回答1: I've never used VisualD, but in Mono-D you can just create a project from a dub package descriptor - just create your package.json and select it in the open project dialogue. Adding stuff to the