d

Usage preference between a struct and a class in D language

点点圈 提交于 2019-12-01 13:42:07
问题 When should I define a type as a struct or as a class? I know that struct are value types while classes are reference types. So I wonder, for example, should I define a stack as a struct or a class? 回答1: Reason #1 to choose struct vs class: classes have inheritance, structs do not. If you need polymorphism, you must use classes. Reason #2: structs are normally value types (though you can make them reference types if you work at it). Classes are always reference types. So, if you want a value

OpenGL texture mapping stubbornly refuses to work

若如初见. 提交于 2019-12-01 13:13:12
I'm writing a 2D game using SDL and OpenGL in the D programming language. At the moment it simply tries to render a texture-mapped quad to the screen. Problem is, the whole texture-mapping part doesn't quite seem to work. Despite the texture apparently loading fine (gets assigned a nonzero texture number, doesn't cause glGetError to return values other than zero), the quad is rendered with the last color set in glColor, entirely ignoring the texture. I've looked for common reasons for texture mapping to fail, including this question , to no avail. The image file being loaded is 64x64, a valid

How would you approach using D in a embedded real-time environment?

两盒软妹~` 提交于 2019-12-01 03:06:56
To all those familiar with D programming language , how would go about using it in a embedded real-time environment? I understand that it's original design is not targeted for real-time embedded environments, but this question is more about how would you go about making real-time capability happen. Which constructs of the language would be indispensable? Which constructs do you see would be a problem? Has anyone successfully used it in a embedded system? Any other thoughts or suggestions would be great. D isn't really meant for use in real-time applications, mostly because some language

How to cast a char* to string in D?

萝らか妹 提交于 2019-12-01 02:25:16
问题 I have a standard char pointer which im trying to cast to a string. // string to char* char *x = cast(char*)("Hello World\0"); // char* to string? string x = cast(string)x; string x = cast(immutable(char)[])x; Error! Any ideas how to cast a char* to a string in D? 回答1: Use std.conv.to to convert from char* to string . Use std.string.toStringZ to go the other way. import std.string; import std.stdio; import std.conv; void main() { immutable(char)* x = "Hello World".toStringz(); auto s = to

How to get single keystroke in D2 (Phobos)?

徘徊边缘 提交于 2019-12-01 00:35:15
问题 Is there a simple, cross-platform way to get a single keystroke in D2 using Phobos? For instance, a "Press any key to continue..." prompt, or a Brainfuck interpreter. All the methods I've tried require an Enter keypress before passing the input (getchar(), for instance). 回答1: I've done some research on the matter, and I've found that, while the Phobos library under D 1.0 had exactly what you need in the form of std.c.stdio.getch() , D 2.0 lacks this function. None of the other standard input

How would you approach using D in a embedded real-time environment?

只愿长相守 提交于 2019-11-30 22:16:47
问题 To all those familiar with D programming language, how would go about using it in a embedded real-time environment? I understand that it's original design is not targeted for real-time embedded environments, but this question is more about how would you go about making real-time capability happen. Which constructs of the language would be indispensable? Which constructs do you see would be a problem? Has anyone successfully used it in a embedded system? Any other thoughts or suggestions would

Overhead of exception handling in D

♀尐吖头ヾ 提交于 2019-11-30 18:13:33
In the D2 programming language, what are the performance implications of using exception handling? In particular: What if I write no exception handling code? What if I do, but no exceptions are ever thrown? What if I do, and exception are thrown? Does exception handling cause any optimization opportunities to be missed? Can exception handling be disabled like it can in many (most?) C++ implementations? I know that almost all commercial game development studios disable exception handling in their C++ due to the performance implications and increased development time associated with correctly

How does memchr() work under the hood?

跟風遠走 提交于 2019-11-30 13:56:08
问题 Background: I'm trying to create a pure D language implementation of functionality that's roughly equivalent to C's memchr but uses arrays and indices instead of pointers. The reason is so that std.string will work with compile time function evaluation. For those of you unfamiliar w/ D, functions can be evaluated at compile time if certain restrictions are met. One restriction is that they can't use pointers. Another is that they can't call C functions or use inline assembly language. Having

Examples of what D’s templates can be used for

こ雲淡風輕ζ 提交于 2019-11-30 12:35:22
问题 I hear that the D language has powerful metaprogramming features for executing functions at compile time. That sounds very exciting, but I find it difficult to think of practical examples of things that are hard to accomplish without them. Can anyone give some examples of situations where D's metaprogramming features comes in very handy? 回答1: One really cool and practical usage of compile time function execution is for generating code at compile time, possibly from config files, or maybe

Where to find algorithms for standard math functions?

随声附和 提交于 2019-11-30 11:51:26
问题 I'm looking to submit a patch to the D programming language standard library that will allow much of std.math to be evaluated at compile time using the compile-time function evaluation facilities of the language. Compile-time function evaluation has several limitations, the most important ones being: You can't use assembly language. You can't call C code or code for which the source is otherwise unavailable. Several std.math functions violate these and compile-time versions need to be written