Re: How often I should be using const? Is it useless/overrated?

2022-11-18 Thread Dennis via Digitalmars-d-learn
On Friday, 18 November 2022 at 11:51:42 UTC, thebluepandabear wrote: A question I have been thinking about whilst using D is how often I should be using const. This should be a good read for you: [Is there any real reason to use

Re: Making sense out of scope and function calls

2022-11-13 Thread Dennis via Digitalmars-d-learn
On Sunday, 13 November 2022 at 19:06:40 UTC, 0xEAB wrote: Why does only the latter sample compile? The former leads to the following warning: Can you please provide a full example? I'm missing the definitions of _headers, hstring, values, and I suspect there's at least one `@safe` annotation

Re: dmd as a library

2022-11-09 Thread Dennis via Digitalmars-d-learn
On Tuesday, 8 November 2022 at 05:48:54 UTC, vushu wrote: Ah thanks that's nice to have some examples. Here's an example of tools using dmd as a library: https://github.com/jacob-carlborg/dlp

Re: Hipreme's #4 Tip of the day - Don't use package.d

2022-11-05 Thread Dennis via Digitalmars-d-learn
On Friday, 4 November 2022 at 10:57:12 UTC, Hipreme wrote: 3. I'm currently having a bug on my API module that every duplicated file name, even when located at different directories(modules), are generating duplicate symbol. The major problem is that this is currently undebuggable, as the

Re: how to benchmark pure functions?

2022-10-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 October 2022 at 17:17:01 UTC, ab wrote: How can I prevent the compiler from removing the code I want to measure? With many C compilers, you can use volatile assembly blocks for that. With LDC -O3, a regular assembly block also does the trick currently: ```D void main() {

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Dennis via Digitalmars-d-learn
On Wednesday, 12 October 2022 at 10:09:31 UTC, Steven Schveighoffer wrote: I'm actually very surprised that just wrapping the statement in an == expression doesn't do the trick, what is the possible logic behind outlawing that? I looked into it, there are actually two different places where

Re: How to workaround assignment not allowed in a condition?

2022-10-12 Thread Dennis via Digitalmars-d-learn
On Wednesday, 12 October 2022 at 02:15:55 UTC, Steven Schveighoffer wrote: Porting some C code to D This results in an error: I had the same issue, where the pattern was this: ```C void f() { int err; if (err = some_api_call()) { printCode(err); return; } if

Re: Convert array of simple structs, to C array of values

2022-10-03 Thread Dennis via Digitalmars-d-learn
On Monday, 3 October 2022 at 07:45:47 UTC, Chris Katko wrote: I know there's gotta be some simple one liner function in D, but I can't think of it. I don't know if you're looking for type safety, but you can just do `cast(float*) values.ptr;` or `cast(float[]) values[]`.

Re: can not take const struct member address at CTFE , is this a bug?

2022-09-15 Thread Dennis via Digitalmars-d-learn
On Thursday, 15 September 2022 at 04:13:56 UTC, test123 wrote: I hope we have github bugs. It's being worked on. Please help me create a bug report if who has free time and bugs account. Here you go: https://issues.dlang.org/show_bug.cgi?id=23336

Re: need help to translate C into D

2022-09-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 11:03:30 UTC, test123 wrote: and upb_MiniTable_Enum can include a lot diff types. (for example mixed diff size upb_MiniTable_Enum) I think you'll need a `void*` array then, since pointers to different structs can all implicitly convert to `void*`.

Re: need help to translate C into D

2022-09-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 10:45:03 UTC, test123 wrote: Is there a way to init the __gshared fixed length upb_MiniTable_Enum array ? I don't think so. You could leave your array typed as `validate_KnownRegex_enum_init_type` and access it through a function that casts it to

Re: need help to translate C into D

2022-09-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 September 2022 at 09:43:46 UTC, test123 wrote: This will not work since the C have no array like D. You can use a 0-size static array: ```D struct mystruct { uint32_t mask_limit; // Limit enum value that can be tested with mask. uint32_t value_count; // Number of

Re: Validate static asserts

2022-09-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 September 2022 at 16:41:54 UTC, Andrey Zherikov wrote: What's about new `compileOutput` trait that returns compiler output? ```d static assert(__traits(compileOutput, { }) == "message"); ``` As a compiler dev, that sounds terrifying. It would make basically every change to

Re: Reference to an unresolved external symbol

2022-09-07 Thread Dennis via Digitalmars-d-learn
On Wednesday, 7 September 2022 at 10:14:22 UTC, Injeckt wrote: I guess you right. But I don't know how i gonna link libs when I'm using "dmd main.d". Another way is to add this to your code: ```D pragma(lib, "User32"); ```

Re: Compile time int to string conversion in BetterC

2022-08-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 17 August 2022 at 08:44:30 UTC, Ogi wrote: Maybe I’m missing something? I had the same problem, and came up with the following trick: ```D enum itoa(int i) = i.stringof; enum major = 3; enum minor = 2; enum patch = 1; enum versionString = itoa!major ~ "." ~ itoa!minor ~ "." ~

Re: Programs in D are huge

2022-08-16 Thread Dennis via Digitalmars-d-learn
On Tuesday, 16 August 2022 at 08:25:18 UTC, Diego wrote: It seams huge in my opinion for an empty program What are the best practices to reduce the size? The problem is that the druntime, the run time library needed to support many D features, is large and linked in its entirety by default.

Re: Some user-made C functions and their D equivalents

2022-07-28 Thread Dennis via Digitalmars-d-learn
On Wednesday, 27 July 2022 at 18:19:34 UTC, pascal111 wrote: The library link: https://github.com/pascal111-fra/turbo-c-programs/blob/main/COLLECT2.H It would help if the functions had a comment explaining what they're supposed to do, but it looks like most of them are string functions. In

Re: BetterC Name Mangling Linker Errors

2022-07-27 Thread Dennis via Digitalmars-d-learn
On Wednesday, 27 July 2022 at 12:26:59 UTC, MyNameHere wrote: ```d void Main(void* Instance) { WNDCLASSEXA WindowClass; ``` This is equivalent to `WNDCLASSEXA WindowClass = WNDCLASSEXA.init;` If the struct's fields all initialize to 0, the compiler would simply set the variable's bytes

Re: Expanding CTFE code during compilation

2022-07-20 Thread Dennis via Digitalmars-d-learn
On Wednesday, 20 July 2022 at 00:33:06 UTC, Azi Hassan wrote: Where did you find it though ? I checked dmd --help and man dmd before making this thread, but to no avail. It was implemented as an internal debugging tool, not a documented feature: https://github.com/dlang/dmd/pull/6556 It

Re: Expanding CTFE code during compilation

2022-07-19 Thread Dennis via Digitalmars-d-learn
On Tuesday, 19 July 2022 at 21:43:01 UTC, Azi Hassan wrote: I'm wondering if the offers has the option of executing the parts that can be evaluated at compile time and then replacing them with the result of this evaluation. Try the `-vcg-ast` flag: ```D import object; import std; void main()

Re: Enforce not null at compile time?

2022-06-20 Thread Dennis via Digitalmars-d-learn
On Monday, 20 June 2022 at 17:48:48 UTC, Antonio wrote: Is there any way to specify that a variable, member or parameter can't be null? Depends on the type. Basic types can't be null. Pointers and classes can always be `null`, though you could wrap them in a custom library type that doesn't

Re: Whats the proper way to write a Range next function

2022-06-15 Thread Dennis via Digitalmars-d-learn
On Wednesday, 15 June 2022 at 13:52:24 UTC, Christian Köstlin wrote: looks like there should be tons of annotations/attributes on it. Because you have a template function, most attributes will be inferred based on the Range type. `const` is not inferred, but `popFront` mutates so it doesn't

Re: C-like static array size inference - how?

2022-06-07 Thread Dennis via Digitalmars-d-learn
On Tuesday, 7 June 2022 at 00:20:31 UTC, Ali Çehreli wrote: > it's complaining about TypeInfo being absent. What an unfortunate error message! Trying writeln() causes equally weird error messages. Walter just improved it! https://github.com/dlang/dmd/pull/14181 Perhaps try a [nightly

Re: Unexplainable behaviour with direct struct assignment.

2022-05-18 Thread Dennis via Digitalmars-d-learn
On Wednesday, 18 May 2022 at 20:05:05 UTC, HuskyNator wrote: This will print: ``` 0 50 nan ``` Which compiler and flags are you using? For me it just prints 50, you might be stumbling on some (old) bugs in the DMD backend with floating point registers. Examples of such bugs are:

Re: Including C sources in a DUB project

2022-05-10 Thread Dennis via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 20:50:12 UTC, Alexander Zhirov wrote: And if there are two compilers in the system - `dmd` and `ldc`, which compiler chooses `dub.json`? It depends on whether your DMD or LDC installation comes first in your PATH environment variable. Both ship with a `dub`

Re: Including C sources in a DUB project

2022-05-10 Thread Dennis via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 17:19:23 UTC, jmh530 wrote: It would be nice if dub included a directory of example configurations for common issues like this. It has an example directory: https://github.com/dlang/dub/tree/master/examples If your configuration is missing, you could make a Pull

Re: dip1000 return scope dmd v 2.100

2022-05-06 Thread Dennis via Digitalmars-d-learn
On Friday, 6 May 2022 at 09:24:06 UTC, vit wrote: It look like examples at page https://dlang.org/spec/function.html#ref-return-scope-parameters are no longer relevant. They were recently updated to match the implementation in 2.100. What difference are between `return scope`, `scope return`

Re: DMD failed with exit code -1073741819

2022-05-03 Thread Dennis via Digitalmars-d-learn
On Tuesday, 3 May 2022 at 18:22:49 UTC, jmh530 wrote: Does anyone have any idea what causes these types of errors? Sounds like a stack overflow, maybe your code has a complex/recursive part that makes DMD's call stack very deep.

Re: T... args!

2022-04-29 Thread Dennis via Digitalmars-d-learn
On Friday, 29 April 2022 at 15:13:08 UTC, Tejas wrote: It's not a keyword yet it's recognised specially by the compiler... What? It's not really recognized by the compiler, there's a little bit of magic to print `string` in outputted D code (e.g. error messages) instead of

Re: Is T.init allowed?

2022-04-29 Thread Dennis via Digitalmars-d-learn
On Friday, 29 April 2022 at 11:30:49 UTC, Andrey Zherikov wrote: Is it a compiler issue so this shouldn't be allowed? Members called `init` are in the process of being deprecated, see: https://github.com/dlang/dmd/pull/12512

Re: CTFE and BetterC compatibility

2022-04-28 Thread Dennis via Digitalmars-d-learn
On Thursday, 28 April 2022 at 12:10:44 UTC, bauss wrote: On Wednesday, 27 April 2022 at 15:40:49 UTC, Adam D Ruppe wrote: but this got killed due to internal D politics. A pity. A tale as old as time itself In this case, it was actually a trailing whitespace in the changelog entry making

Re: How do I get the screen resolution?

2022-04-28 Thread Dennis via Digitalmars-d-learn
On Thursday, 28 April 2022 at 11:22:15 UTC, Alexander Zhirov wrote: Are there any methods to get the screen resolution? Example with GLFW: https://github.com/dkorpel/glfw-d/blob/7a1eec60d427617c098d0e54a26cba796956a976/examples/empty-window/app.d#L118 Note that there can be multiple

Re: Library for image editing and text insertion

2022-04-27 Thread Dennis via Digitalmars-d-learn
On Wednesday, 27 April 2022 at 07:42:31 UTC, Alexander Zhirov wrote: ```d ~/programming/d/pic $ dmd app.d ``` Try passing the `-i` flag: `dmd -i app.d`. This way, imported modules are actually compiled and linked too. Currently it looks like you import arsd, but then don't link the library,

Re: unexpected noreturn behavior

2022-04-21 Thread Dennis via Digitalmars-d-learn
On Thursday, 21 April 2022 at 12:41:08 UTC, WebFreak001 wrote: which I think is a little bug-prone, but at least that would solve my issues. What issue do you have with it returning `true`? Note that this compiles: ```D @safe: import std.sumtype; void main() { SumType!(int, string) s =

Re: Install D lang on Windows 10 : an installation step by step tutorial made by a beginner who loves D !

2022-04-18 Thread Dennis via Digitalmars-d-learn
On Monday, 18 April 2022 at 08:22:43 UTC, SMAOLAB wrote: I tried to install D on a Windows 10 but encountered some difficulties (even though I was reading the official D langage tutorial available on the official website). What went wrong when you used the DMD installer? Installing Visual

Re: scope variable `b` assigned to `a` with longer lifetime (-dip1000)

2022-04-09 Thread Dennis via Digitalmars-d-learn
On Saturday, 9 April 2022 at 10:39:33 UTC, vit wrote: Why doesn't this code compile? `proxySwap1` is lying about its attributes. It says `rhs` is `scope`, but it escapes by assignment `this.ptr = rhs.ptr;`. The compiler doesn't raise an error because it's marked `@trusted`. `proxySwap2` is

Re: Check if Key exists in Associative Array using D language.

2022-04-05 Thread Dennis via Digitalmars-d-learn
On Tuesday, 5 April 2022 at 11:26:27 UTC, BoQsc wrote: I'd like to know if there is similar function: that can check if a **key** inside a [Associative Array][2] can be found. You can use the `in` operator for that: https://dlang.org/spec/hash-map.html#testing_membership

Re: Embarrassed to ask this question because it seems so trivial but genuinely curious...

2022-01-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 January 2022 at 17:42:09 UTC, WhatMeWorry wrote: So I guess my question is, is this just a matter of esthetics or is some more nuanced goal at work here? It doesn't matter much for constructors, but in general, the problem with placing qualifiers in front is that it looks

Re: How to create a function that behaves like std.stdio.writeln but prepends output with __FILE__:_LINE_

2022-01-25 Thread Dennis via Digitalmars-d-learn
On Tuesday, 25 January 2022 at 12:11:01 UTC, JG wrote: Any ideas how one can achieve what is written in the subject line? ```D void f(T...)(auto ref T args, string file = __FILE__, int line = __LINE__) { writeln(file, ":", line, ": ", args); } ```

Re: Returning value by ref does not create a ref. Is this intentional?

2022-01-05 Thread Dennis via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 05:38:45 UTC, Tejas wrote: The entire reason I wanted to get a `ref` was so that I can avoid the `*` :( I don't know what the real code behind the reduced example is, but maybe you can structure your code such that the subsequent modification `c = 10` happens

Re: Thread exits immediately with no reason.

2021-12-21 Thread Dennis via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 07:08:53 UTC, bauss wrote: It should at the very least warn people about functions that may throw errors. What is "It"? I was looking to make a spec PR, but it already says here: https://dlang.org/spec/function.html#nothrow-functions Nothrow functions can

Re: Attributes (lexical)

2021-11-25 Thread Dennis via Digitalmars-d-learn
On Thursday, 25 November 2021 at 12:09:55 UTC, Dennis wrote: This should also be fixed in the spec. Filed as: Issue 22543 - [spec] grammar blocks use unspecified notation: https://issues.dlang.org/show_bug.cgi?id=22543 Issue 22544 - [spec] C++ and Objective-C are not single tokens

Re: Attributes (lexical)

2021-11-25 Thread Dennis via Digitalmars-d-learn
On Thursday, 25 November 2021 at 10:41:05 UTC, Rumbu wrote: Well: ``` #line IntegerLiteral Filespec? EndOfLine ``` Having EndOfLine at the end means for me that there are no other EOLs between, otherwise this syntax should pass but it's not (DMD last): ```d #line 12 "source.d" ``` The

Re: Attributes (lexical)

2021-11-25 Thread Dennis via Digitalmars-d-learn
On Thursday, 25 November 2021 at 08:06:27 UTC, rumbu wrote: Also, this works also for #line, even if the specification tells us that all tokens must be on the same line Where does it say that?

Re: What is D's "__debugbreak()" equivalent?

2021-10-28 Thread Dennis via Digitalmars-d-learn
On Wednesday, 27 October 2021 at 16:54:49 UTC, Simon wrote: What is the equivalent in D? With LDC, you have: ```D import ldc.intrinsics: llvm_debugtrap; ``` Combining that with previous answers, you can make something like this: ```D void debugbreak() nothrow @nogc @trusted {

Re: Unexpected path of execution

2021-10-19 Thread Dennis via Digitalmars-d-learn
On Tuesday, 19 October 2021 at 16:20:39 UTC, Charles Hixson wrote: core.exception.RangeError@source/freqs.d(32): Range violation ??:? _d_arrayboundsp [0x56041325a70d] ??:? _Dmain [0x560413233beb] DMD64 D Compiler v2.097.2 By the way, if you upgrade to 2.098.0, you get a

Re: Obtaining type and value of a variable named in another variable

2021-10-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 October 2021 at 19:28:04 UTC, DLearner wrote: How does one obtain from strVar: 1. The type of fooVar; `typeof(mixin(strVar))` 2. The value of fooVar? `mixin(strVar)`

Re: __traits(compiles) is true with warnings as errors

2021-10-15 Thread Dennis via Digitalmars-d-learn
On Thursday, 14 October 2021 at 11:08:24 UTC, bauss wrote: What could be useful is a new trait (to not break existing code) like __traits(warning, ...) which does the same as __traits(compiles) but also checks whether the arguments would cause a warning by the compiler. N! Warnings suck.

Re: avoid codegen pass

2021-10-02 Thread Dennis via Digitalmars-d-learn
On Saturday, 2 October 2021 at 16:57:48 UTC, max haughton wrote: Do you have optimizations turned on? i.e. are you compiling with -O by accident? Not needed, it's declared: ```D pragma(inline, true) @property _timezone() @safe const pure nothrow @nogc ``` DMD does inlining in the frontend,

Re: How can we view source code that has been generated (say via "static foreach") ?

2021-09-17 Thread Dennis via Digitalmars-d-learn
On Wednesday, 15 September 2021 at 19:59:43 UTC, james.p.leblanc wrote: However, with various combinations of templates, UDAs, and mixins it has not been easy. Apart from -mixin, there's also the undocumented -vcg-ast switch that prints the AST before code generation, showing instantiated

Re: Development of the foundation of a programming language

2021-09-13 Thread Dennis via Digitalmars-d-learn
On Monday, 13 September 2021 at 03:21:37 UTC, leikang wrote: Are there any recommended books or videos to learn about the principles of compilation? What else should I learn besides the principles of compilation? Check out this video: [DConf 2016 Day 2 Keynote: Spelunking D Compiler

Re: Phobos Unittest

2021-09-04 Thread Dennis via Digitalmars-d-learn
On Saturday, 4 September 2021 at 09:42:46 UTC, Per Nordlöw wrote: Yes, but they are lexed and parsed, right? Right, but that's the case regardless of `version(StdUnittest)`.

Re: C to D convertor

2021-08-24 Thread Dennis via Digitalmars-d-learn
On Saturday, 21 August 2021 at 08:14:22 UTC, Виталий Фадеев wrote: Any more ? CPP2D https://github.com/lhamot/CPP2D

Re: Union member positions?

2021-08-17 Thread Dennis via Digitalmars-d-learn
On Tuesday, 17 August 2021 at 13:46:22 UTC, z wrote: Is it possible to set a "position" on a union member? You can use anonymous `struct` and `union` blocks. ```D union UnionExample{ uint EAX; struct { //upper union { ushort EAHX; struct {

Re: .tupleof for static array

2021-08-10 Thread Dennis via Digitalmars-d-learn
Thanks for this solution as well. On Tuesday, 10 August 2021 at 13:10:23 UTC, Paul Backus wrote: Would definitely be nice to have this in the language, though. Do you know more use cases for this?

Re: .tupleof for static array

2021-08-10 Thread Dennis via Digitalmars-d-learn
Thanks! I was considering turning the static array into an AliasSeq directly, but casting it to a struct and doing tupleof on that is pretty smart. On Tuesday, 10 August 2021 at 12:50:55 UTC, jfondren wrote: And I don't see very many static-array-generic functions in Phobos. Indeed, static

.tupleof for static array

2021-08-10 Thread Dennis via Digitalmars-d-learn
```D struct Vec { float x, y, z; } void setPosition(float x, float y, float z) { } void main() { Vec posS = Vec(10, 20, 30); setPosition(posS.tupleof); // pass float[3] posA = [10, 20, 30]; setPosition(posA.tupleof); // Error: no property `tupleof` for type `float[3]` }

Re: Tracy

2021-08-08 Thread Dennis via Digitalmars-d-learn
On Sunday, 8 August 2021 at 01:37:42 UTC, SealabJaster wrote: Could this be fixed? Or is this intentional? Of course it *could*, anyone can go to [the dlang wiki](https://wiki.dlang.org/LDC) and add a page for it. Johan Engelen is still working on [improving the

Re: Tracy

2021-08-07 Thread Dennis via Digitalmars-d-learn
On Friday, 6 August 2021 at 12:30:16 UTC, JG wrote: I guess this means that tracy has been integrated? If this is so is it documented anywhere how to use it? Stefan Koch's WIP tracy integration in DMD is completely separate from Johan Engelen's time tracing added to LDC in 1.25.0. Note that

Re: Build time

2021-07-23 Thread Dennis via Digitalmars-d-learn
On Friday, 23 July 2021 at 18:53:06 UTC, JG wrote: Any suggestion on how to try and improve the build time. I am currently using dub. You can try profiling it with LDC 1.25 or later. Add this to dub.sdl: ``` dflags "--ftime-trace" platform="ldc" dflags "--ftime-trace-file=./my-trace.json"

Re: Creating immutable arrays in @safe code

2021-07-17 Thread Dennis via Digitalmars-d-learn
On Saturday, 17 July 2021 at 12:05:44 UTC, ag0aep6g wrote: Hm, as far as I understand, "strongly pure" doesn't require `immutable` parameters. `const` should be enough. The spec says: "A strongly pure function has no parameters with mutable indirections" [1]. I just took the description from

Re: Creating immutable arrays in @safe code

2021-07-17 Thread Dennis via Digitalmars-d-learn
On Saturday, 17 July 2021 at 05:44:24 UTC, ag0aep6g wrote: I tried doing that, but `-preview=dip1000` causes trouble. This fails: (...) I'm not sure what's going on. I'm not completely caught up, but from what I see, pure and immutable have a history of issues: [Issue 11503 - Type system

Re: Creating immutable arrays in @safe code

2021-07-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 July 2021 at 20:45:11 UTC, H. S. Teoh wrote: Have you tried `pure`? The code in question is all `@safe pure nothrow`.

Re: Creating immutable arrays in @safe code

2021-07-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 July 2021 at 20:39:41 UTC, Ali Çehreli wrote: So to me, newly created data should be mutable for the most usability. It's clear that I stripped away too much context with the toy examples, so let me try to add some back. I don't like forcing the use of `immutable` in general,

Creating immutable arrays in @safe code

2021-07-16 Thread Dennis via Digitalmars-d-learn
I like passing around immutable data, but I don't like creating it. Here are some toy examples to illustrate: ```D immutable(int)[] positive(int[] input) @safe { return input.filter!(x => x > 0).array; } ``` Error: cannot implicitly convert expression `array(filter(input))` of type

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: But reading/writing, closing these file descriptors is always the same. For sockets you'd typically use `recv` and `send` instead or `read` and `write` because the former give extra options and the latter don't work on

Re: to compose or hack?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Wednesday, 7 July 2021 at 01:44:20 UTC, Steven Schveighoffer wrote: But it got me thinking, how often do people roll their own vs. trying to compose using existing Phobos nuggets? When there's not an obvious/simple way to do something by composing ranges, I tend to just give up and write

Re: assign to property 2 values

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 10:19:59 UTC, Виталий Фадеев wrote: It possible in current version 2.097 ? If you `import std.typecons` you can do: ```D element.border = tuple(1, solid).expand; ``` But it's not pretty. I suggest either calling the function regularly, or combing all settings in a

Re: Can I make system calls directly from D?

2021-07-09 Thread Dennis via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C If with directly means 'without calling any C function' you can use inline assembly: ```D version(linux) void

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 23:31:57 UTC, Antonio wrote: "It works as described in the manual, not as expected" (from MySQL haters club :-p) . Yeah, 50/285 people answering the question "What language features do you miss?" chose "UFCS for local symbols" in the [State of D survey

Re: UFCS doubt

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 22:24:26 UTC, Antonio wrote: I supossed that ```mfp(c,20)``` and ```c.mfp(20)``` should be equivalent because UFCS in second example, but it is not... why? UFCS does not work for nested functions. Functions declared in a local scope are not found when searching

Re: Trivial simple OpenGl working example

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 14:20:16 UTC, Виталий Фадеев wrote: Has dub flag for disable "warnings are treated as errors" ? You have to edit the package file to include `buildRequirements "allowWarnings"`, see https://dub.pm/package-format-sdl.html#build-requirements

Re: Trivial simple OpenGl working example

2021-07-08 Thread Dennis via Digitalmars-d-learn
On Thursday, 8 July 2021 at 13:51:51 UTC, Виталий Фадеев wrote: I searching trivial simple D/OpenGL working in 2021 year example. https://github.com/dkorpel/glfw-d/tree/master/examples/triangle-gl Uses bindbc-opengl + glfw-d (my package), example uses OpenGL 3.3. Should works on Windows and

Re: How to disable assigning a value to a property?

2021-07-06 Thread Dennis via Digitalmars-d-learn
On Tuesday, 6 July 2021 at 10:06:11 UTC, Jack Applegame wrote: How to disable `register.clock = 10;` but allow `register.clock(1) = 10;`? I want to get a compilation error on `register.clock = 10;` We're [still awaiting formal assessment on

Re: anonymous functions and scope(exit)

2021-07-03 Thread Dennis via Digitalmars-d-learn
On Saturday, 3 July 2021 at 17:20:47 UTC, Luis wrote: scope(exit) inside of a anonymous functions, it's never called. I think the compiler infers the function `nothrow` since you don't throw any `Exception`, only an `Error`. Errors represent unrecoverable bugs, after which the program is in

Re: float price; if (price == float.nan) { // initialized } else { // uninitialized } ... valid ?

2021-06-30 Thread Dennis via Digitalmars-d-learn
On Wednesday, 30 June 2021 at 03:52:51 UTC, someone wrote: at least I can do nulls with strings since it a class :) A `string` is not a class but an array, an `immutable(char)[]`. For arrays, `null` is equal to an empty array `[]`. ```D void main() { string s0 = null; string s1 = [];

Re: How to I get pointer to an Array and cast to a void * and back ?

2021-06-24 Thread Dennis via Digitalmars-d-learn
On Thursday, 24 June 2021 at 14:06:11 UTC, seany wrote: void f() { a[] * rd; // DO SOME WORK HERE this.dataSet = & rd_flattened; rd = cast (a [] *) dataSet; write("length of rd is : "); writeln((*rd).length); // <--- this works.. // do some work

Re: BetterC, int to string?

2021-06-18 Thread Dennis via Digitalmars-d-learn
On Friday, 18 June 2021 at 09:05:38 UTC, Mike Brown wrote: im doing this in a compile time function as well. If it's a compile time string you can use mixin()

Re: semi-final switch?

2021-06-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: Any ideas on better ways to handle this? I've had such a situation before too where I want to switch over enums I read from an ELF file which can't be assumed to be correct, but I also don't want to forget one. For a

Re: What is this undefined reference with -betterC about?

2021-06-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 16:27:13 UTC, Dennis wrote: It has to be a linker error, dmd cannot know at the time of compiling project A how project B is going to be compiled and vice versa. Well I suppose you could use a specific dub configuration, maybe giving 'hostname' a targetType

Re: What is this undefined reference with -betterC about?

2021-06-16 Thread Dennis via Digitalmars-d-learn
On Wednesday, 16 June 2021 at 14:38:10 UTC, jfondren wrote: What do I change to 1. a script like this that uses hostname 2. the hostname module so that both can be built with -betterC when and only when the script is using -betterC? That's currently the situation: you can only build when both

Re: How to translate this C macro to D mixin/template mixin?

2021-06-15 Thread Dennis via Digitalmars-d-learn
On Tuesday, 15 June 2021 at 12:18:26 UTC, VitaliiY wrote: It's simple with STARTDATA as mixin, but STOREBITS and ADDBITS use variables defined in STARTDATA scope, so I can't understand how to do mixin template with it. If the code duplication isn't too bad, consider just expanding the C

Re: difficulty with rectangular arrays

2021-06-11 Thread Dennis via Digitalmars-d-learn
On Friday, 11 June 2021 at 08:30:29 UTC, Moth wrote: what's going on? It's a bug: [Issue 19178 - Static initialization of 2d static arrays in structs produces garbage or doesn't compile sometimes](https://issues.dlang.org/show_bug.cgi?id=19178)

Re: Flaoting point operations : unexpected results

2021-06-10 Thread Dennis via Digitalmars-d-learn
On Thursday, 10 June 2021 at 19:37:36 UTC, seany wrote: However, i sometimes see, that the results are _radically_ different. Are you using uninitialized memory or multi-threading?

Re: For fun, and executable lame joke

2021-05-31 Thread Dennis via Digitalmars-d-learn
On Monday, 31 May 2021 at 03:44:15 UTC, btiffin wrote: Is there a way to make that less codey, more jokey, *but still compile and execute the hip hip array*? ```D import std; alias cheer = each!writeln; void main() { D(); } void D() { cheer = ["hip", "hip"].array; } ```

Re: Compiler Explorer Assembly Output for C, C++ and D (dlang)

2021-05-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 May 2021 at 10:27:42 UTC, Tariq Siddiqui wrote: Thanks for your answer, -betterC works well with simple code but when using templates in code -betterC compilation failed. Templates are supported in -betterC, what's not supported can be found here:

Re: Compiler Explorer Assembly Output for C, C++ and D (dlang)

2021-05-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 May 2021 at 08:47:50 UTC, Tariq Siddiqui wrote: - What are these additional lines? D generates extra symbols per module for things like module constructors, unittests and class introspection (I think). - How can I remove these lines from being generated? Pass the

Re: ugly and/or useless features in the language.

2021-05-23 Thread Dennis via Digitalmars-d-learn
On Sunday, 23 May 2021 at 14:13:36 UTC, Alain De Vos wrote: This one compiles without any problem. You annotated main `@trusted`, which means you want the compiler to assume it to be `@safe` without checking it. Mark it `@safe` and it reports: Error: address of variable `a` assigned to `q`

Re: struct destructor

2021-05-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 May 2021 at 17:55:17 UTC, Alain De Vos wrote: Feature request, a function old which does the opposite of new, allowing deterministic,real-time behavior and memory conservation. You can use [object.destroy](https://dlang.org/phobos/object.html#.destroy) to destruct, and

Re: Scope of import

2021-05-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 May 2021 at 11:38:22 UTC, Adam D. Ruppe wrote: * rdmd runs the program too, dmd -i just compiles. You run the program separately. You can do `dmd -i -run main.d`

Re: bindbc.sfml , sfVideoMode , Error: undefined identifier

2021-05-08 Thread Dennis via Digitalmars-d-learn
On Saturday, 8 May 2021 at 09:05:18 UTC, Alain De Vos wrote: I must doing something wrong ? Did you define the `SFML_Graphics` version like in the README of bindbc-sfml?

Re: Measure cpu time

2021-05-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 May 2021 at 08:52:13 UTC, Dennis wrote: If you want to use it on Windows as well, this is a code snippet I wrote for that: For completeness, the imports it uses: ```D version(Windows) { import core.sys.windows.windows; import core.sys.windows.psapi:

Re: Measure cpu time

2021-05-07 Thread Dennis via Digitalmars-d-learn
On Friday, 7 May 2021 at 08:25:43 UTC, Andre Pany wrote: Is there some equivalent function in Phobos to get the cpu time on linux? I don't think so, but you can use `core.sys.posix.sys.resource: rusage`. If you want to use it on Windows as well, this is a code snippet I wrote for that:

Re: How to check for combinations of versions

2021-05-05 Thread Dennis via Digitalmars-d-learn
On Wednesday, 5 May 2021 at 15:03:16 UTC, Blatnik wrote: Is there any way to check for multiple conditions in a `version` statement? No, and that's by design to discourage complex version logic. The recommended approach is: ```D version (Version_A) version = Cool_Feature_Supported; version

Re: ioctl to set mixer volume

2021-04-16 Thread Dennis via Digitalmars-d-learn
On Friday, 16 April 2021 at 17:50:13 UTC, Alain De Vos wrote: The following very simple low level C-function simply sets the mixer volume. How to convert this simple function to dlang ? ``` void mixer_setlevel_stereo(int mixfd,int dev,int left,int right) { left+=256*right; #int_ioctl(int fd,

Re: Endianness - How to test code for portability

2021-03-12 Thread Dennis via Digitalmars-d-learn
On Friday, 12 March 2021 at 05:53:40 UTC, Preetpal wrote: This is not an important issue to me but I was just curious to see if anyone actually tests for portability issues related to endianness by compiling their D Lang code for a big endian architecture and actually running it on that

Re: Two functions with different args. Taking address of the one

2021-03-11 Thread Dennis via Digitalmars-d-learn
On Thursday, 11 March 2021 at 12:56:34 UTC, Виталий Фадеев wrote: What right way to call function directly with selecting one of two ? If they are not nested functions, you can also do: ``` // Separate names void processKey (ref MouseKeyEvent event) {...} void processMove(ref MouseMoveEvent

Re: Introspection of exceptions that a function can throw

2021-02-24 Thread Dennis via Digitalmars-d-learn
On Wednesday, 24 February 2021 at 19:38:53 UTC, Mark wrote: Is there a way to obtain a list, at compile-time, of all the exception types that a function might throw (directly or through a call to another function)? No, since this is not known at compile-time. See:

Re: Why am I getting a dividing by zero error message

2021-01-28 Thread Dennis via Digitalmars-d-learn
On Thursday, 28 January 2021 at 18:37:37 UTC, Ruby The Roobster wrote: object.Error@(0): Integer Divide by Zero Why is this happening? Does anybody know? data[0] = (new egg(0,0,"a")); Here you set data[0].y to 0 tempb = data[x].y; In the first iteration, this equals data[0].y which

Re: How can I check to see if template type is an array?

2021-01-19 Thread Dennis via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 22:26:52 UTC, Tim wrote: I need to be able to check in a template whether the type given is an array type so that I can do some different logic. How can I do this? `if(is(T == E[], E))` or `isDynamicArray!T` is you `import std.traits;`

  1   2   3   >