Re: Placement new and @trusted

2025-09-11 Thread Dennis via Digitalmars-d-learn
On Wednesday, 10 September 2025 at 12:29:24 UTC, IchorDev wrote: If anyone has any ideas, please let me know. The trick that's used in druntime is putting the part that still needs to be checked for attributes inside an `if (false)` block, for example: https://github.com/dlang/dmd/blob/c817

Re: result of FFT

2025-07-08 Thread Dennis via Digitalmars-d-learn
On Tuesday, 8 July 2025 at 18:11:27 UTC, Matthew wrote: I can't figure out how the 4096 results of the FFT relate to the frequencies in the input. I tried taking the magnitude of each element, That's correct! What do the 4096 resulting complex numbers represent? The magnitude of each elem

Re: scope parameter has effect only on pointers?

2025-06-23 Thread Dennis via Digitalmars-d-learn
On Monday, 23 June 2025 at 10:37:58 UTC, Dom DiSc wrote: I know, it would be needed to enable generic programming, but I find a function that can take both an int and an int* suspect anyway - this is kind of too generic for my taste. Would you say `HashMap!(Key, Value).opIndex(scope Key)` is t

Re: Pragma msg goes out of memory when supplied with large data.

2025-05-23 Thread Dennis via Digitalmars-d-learn
On Friday, 23 May 2025 at 12:06:00 UTC, realhet wrote: - export: It was possible to export data (20MByte) from the compiler in seconds, using pragma(msg, ...) Just don't touch the large data with CTFE. pragma(msg) is meant to print informative human-readable strings for debugging purposes. I

Re: How to replicate an Error: scope variable `old` assigned to `ref` variable `ctx` with longer lifetime?

2025-05-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 May 2025 at 12:22:44 UTC, matheus wrote: Maybe the compiler it should give an warning in that @safe without ":" when marking all the file? `@safe`, like any attribute, can be applied in multiple ways: ```D // apply to next declaration attr declaration; // apply to a scope of de

Re: How to replicate an Error: scope variable `old` assigned to `ref` variable `ctx` with longer lifetime?

2025-05-13 Thread Dennis via Digitalmars-d-learn
On Tuesday, 13 May 2025 at 11:55:21 UTC, matheus wrote: Unfortunately adding the pointer gives me another error: I added @safe: and replaced `const` with `auto` because casting away const isn't safe. This should do it: ```D // compile with -preview=dip1000 import std; @safe: struct S { int

Re: How to replicate an Error: scope variable `old` assigned to `ref` variable `ctx` with longer lifetime?

2025-05-12 Thread Dennis via Digitalmars-d-learn
On Monday, 12 May 2025 at 21:46:04 UTC, matheus wrote: I saw a post (https://forum.dlang.org/post/aklmfkzqpsraprjfx...@forum.dlang.org) by Dennis where he gives an example: So I'd like to try it out, so I wrote the snippet below: @safe import std; struct S{} Make sure S contains at least o

Re: simple question about UFCS and templates...wasFound(i) works but not i.wasFound()

2025-03-21 Thread Dennis via Digitalmars-d-learn
On Thursday, 20 March 2025 at 16:18:32 UTC, WhatMeWorry wrote: Yup. That was the problem. Thank you. You guys are a sharp. From dmd version 2.111, there will be a better error message in this case. https://github.com/dlang/dmd/pull/21046

Re: Documentation re -betterC compatibility with standard library functions

2025-01-28 Thread Dennis via Digitalmars-d-learn
On Tuesday, 28 January 2025 at 15:00:13 UTC, Jonathan M Davis wrote: but we provide no guarantees that any code that works with -betterC right now will continue to do so, and we do not intend to add -betterC support. So, if you use something from Phobos that happens to work with -betterC today,

Re: whats the best way to write short ciruitable reductions?

2025-01-14 Thread Dennis via Digitalmars-d-learn
On Monday, 13 January 2025 at 21:48:15 UTC, monkyyy wrote: Is there a clean idea someone has? There's no state kept after each reduction step; each comparison is done independently of the previous ones. So this really is just a negated 'find' operation, for which you can use `all`: ```D boo

Re: Super easy struct construction question that I'm embarrassed to ask.

2025-01-13 Thread Dennis via Digitalmars-d-learn
On Friday, 10 January 2025 at 16:57:10 UTC, An wrote: If the compiler flags this as an warning -> he probably notice the problem Lag of error/warn/hint for such case is not helping Happy coding I'm trying out making it an error: https://github.com/dlang/dmd/pull/20696

Re: Super easy struct construction question that I'm embarrassed to ask.

2025-01-09 Thread Dennis via Digitalmars-d-learn
On Thursday, 9 January 2025 at 22:01:59 UTC, WhatMeWorry wrote: this(Location locaction, uint f) { this.location = location; this.f = f; } You misspelled the parameter name 'locaction', so your assignment in the constructor is a no-op: ``` this.location = this.locati

Re: maybe a noreturn issue

2024-12-03 Thread Dennis via Digitalmars-d-learn
On Tuesday, 3 December 2024 at 12:41:18 UTC, Basile B. wrote: What's you're position ? I often see suggestions to raise warnings/errors for ostensibly 'useless constructs', such as unused parameters, if (0), strongly pure functions returning void etc. In my experience, doing this rarely cat

Re: File-like option where the "file contents" comes from a string?

2024-11-27 Thread Dennis via Digitalmars-d-learn
On Wednesday, 27 November 2024 at 01:12:23 UTC, Andy Valencia wrote: Again and again for testing I run into how nice it would be to have an open "File" which has its contents set by the unit test code I don't know what situation you're in so this may not be applicable, but I personally rarely

Re: Negating a short?

2024-11-06 Thread Dennis via Digitalmars-d-learn
On Wednesday, 6 November 2024 at 11:51:41 UTC, Matheus wrote: Shouldn't these two act the same? That would make sense, but you wouldn't make a special case just for that specific expression, and it's hard to find a good rule that generalizes to all expressions.

Re: Negating a short?

2024-11-05 Thread Dennis via Digitalmars-d-learn
On Tuesday, 5 November 2024 at 20:29:08 UTC, Andy Valencia wrote: I still see: tst15.d(6): Error: cannot implicitly convert expression `-cast(int)s` of type `int` to `short` That's right, it only removes the deprecation that requires a double cast to fix, but you still need an explicit cast

Re: Negating a short?

2024-11-05 Thread Dennis via Digitalmars-d-learn
On Tuesday, 5 November 2024 at 17:32:00 UTC, Andy Valencia wrote: I ended up with this, but is negating a short really this problematic, or did I miss something? This is a relic from when integer promotion was added to unary operators to match the behavior of C compilers. You can add the `-pr

Re: ImportC question

2024-10-29 Thread Dennis via Digitalmars-d-learn
On Tuesday, 29 October 2024 at 16:14:22 UTC, DLearner wrote: On Tuesday, 29 October 2024 at 15:49:13 UTC, ryuukk_ wrote: https://learn.microsoft.com/en-us/visualstudio/ide/reference/command-prompt-powershell?view=vs-2022 Similar message from Powershell: Whether it's CMD/Powershell isn't impo

Re: Is there a skipOver function for InputRanges?

2024-10-08 Thread Dennis via Digitalmars-d-learn
On Tuesday, 8 October 2024 at 07:14:28 UTC, realhet wrote: Is there a way to do it nicer with Phobos? You can use `find` with a negated predicate: `find!(x => !x.front.all!isWhite)`

Re: How to evaluate a JSON file at compile time and create a struct out of it?

2024-10-04 Thread Dennis via Digitalmars-d-learn
On Friday, 4 October 2024 at 08:45:49 UTC, holyzantaclara wrote: I am new in D, and started this morning. I found a way to read a file at compile time with `-J.` and `static string content = import("my_json_file.json")` static usually means "give this declaration the same semantics as if it w

Re: importC with struct name and function conflict

2024-08-05 Thread Dennis via Digitalmars-d-learn
On Monday, 5 August 2024 at 11:02:24 UTC, Dakota wrote: This will not work for me. (huge code base I can not change and maintain) You don't have to change the code where the type is defined per se, you just need to put it in any C file that can access the C symbol. clib_helpers.c: ```C #in

Re: Get compile time string of dmd command line options "-os" & "-target"

2024-08-03 Thread Dennis via Digitalmars-d-learn
On Thursday, 1 August 2024 at 04:00:08 UTC, An Pham wrote: pragma(msg, os.stringof...?); pragma(msg, target.stringof...?); There's no built-in way, but you can define it yourself in a helper module: ```D version(Windows) enum os = "windows"; else version(AArch64) enum os = "aarch64";

Re: importC with struct name and function conflict

2024-08-03 Thread Dennis via Digitalmars-d-learn
On Saturday, 3 August 2024 at 05:10:37 UTC, Dakota wrote: How can I get the function and type from importC? is there a auto rename mechanism ? The most pragmatic workaround is to add a typedef to the C code: ```C int S; struct S { int a, b; }; typedef struct S S_t;// add this typedef ```

Re: Prevent self-comparison without taking the address

2024-07-25 Thread Dennis via Digitalmars-d-learn
On Thursday, 25 July 2024 at 11:46:29 UTC, IchorDev wrote: Also just so you know, placing `@safe:` there will not affect the contents of `S`. It has to be inside the struct declaration to affect its contents. That's true for the other function attributes, but `@safe:` actually does penetrate

Re: Unexpected range assignment behaviour

2024-07-19 Thread Dennis via Digitalmars-d-learn
On Friday, 19 July 2024 at 17:20:22 UTC, matheus wrote: couldn't this case for example be caught during the compiling time? The RangeError is only thrown when at runtime, the key doesn't exist, so that can't be caught. The real problem is implicit slicing of static arrays, which I'm not a fan

Re: Unexpected range assignment behaviour

2024-07-19 Thread Dennis via Digitalmars-d-learn
On Friday, 19 July 2024 at 09:34:13 UTC, Lewis wrote: But the value of $ here is 3. Why do I get a RangeError at runtime even though the slice is the correct size (and the same size as the hardcoded one that works)? The range `0 .. 3` has compile time known length, so it gets converted to str

Re: std.container.rbtree has no search method?! e.g. `contains`, `canFind`

2024-07-13 Thread Dennis via Digitalmars-d-learn
On Saturday, 13 July 2024 at 17:41:42 UTC, mw wrote: I cannot find any search method?! e.g. `contains`, `canFind`. Is this a over look? Or there are such functions else where? It's the `in` operator: https://dlang.org/phobos/std_container_rbtree.html#.RedBlackTree.opBinaryRight But indeed, t

Re: Why does this mixin fail to compile?

2024-07-01 Thread Dennis via Digitalmars-d-learn
On Monday, 1 July 2024 at 13:00:55 UTC, ryuukk_ wrote: please stick to what i wrote, i don't want string concatenation, i provide a reduced example from my project, everything should be a single template block, no extra functions other than the append() one Mixin templates are a declaration s

Re: Why does this mixin fail to compile?

2024-07-01 Thread Dennis via Digitalmars-d-learn
On Monday, 1 July 2024 at 09:25:39 UTC, ryuukk_ wrote: This simple mixin fails to compile, anyone know why? ```D mixin implement; mixin template implement() { mixin("struct _gen(T) {"); mixin("}"); } A string mixin must form a complete declaration / statement / expression / type, so

Re: Boneheaded question regarding compilation...

2024-04-02 Thread Dennis via Digitalmars-d-learn
On Tuesday, 2 April 2024 at 18:21:58 UTC, Mike Shah wrote: An easier fix may be perhaps to just use 'dub' and install the glfw dependency. In my talk, I did everything from scratch (my preferred way), though I suspect using dub with glfw-d (https://code.dlang.org/packages/glfw-d) may provide le

Re: Using C header libs with importC

2024-01-08 Thread Dennis via Digitalmars-d-learn
On Monday, 8 January 2024 at 21:56:10 UTC, Renato wrote: but I tried exactly that! Which gives a seg fault. Looks like there's a bug with the -H switch: https://issues.dlang.org/show_bug.cgi?id=24326 But that shouldn't be necessary, you should just be able to import the c file. I also tried

Re: Compiler analysis fault?

2023-12-20 Thread Dennis via Digitalmars-d-learn
On Wednesday, 20 December 2023 at 11:33:22 UTC, DLearner wrote: The code below fails to compile with Error: function `test1.foo` no `return exp;` or `assert(0);` at end of function unless the commented-out assert(0) is included. The compiler basically gives up control flow analysis when enc

Re: Changing behavior of associative array

2023-12-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 16 December 2023 at 21:30:55 UTC, kdevel wrote: If you comment out this line ``` //m[f] = 1; ``` in your main function of your posted code you can catch up with your real programm insofar as you now need a ref parameter here, too. That's because `m[f] = 1` initializes the a

Re: struct initializer

2023-11-30 Thread Dennis via Digitalmars-d-learn
On Thursday, 30 November 2023 at 07:21:29 UTC, Dom DiSc wrote: So, why supporting the (somewhat strange looking) version with curly backets at all? It only works in one special place, so is simply overhead to remember. Again a superfluous way to do the same - but only under specific circumstanc

Re: mixin issue

2023-11-29 Thread Dennis via Digitalmars-d-learn
On Wednesday, 29 November 2023 at 13:31:14 UTC, DLearner wrote: it works but doesn't seem correct. You're mixing in an expression that creates an empty function and calls it. What do you want it to do?

Re: How to use ".stringof" to get the value of a variable and not the name of the variable (identifier) itself?

2023-10-10 Thread Dennis via Digitalmars-d-learn
On Monday, 9 October 2023 at 16:33:32 UTC, rempas wrote: However, in my example, "stringof" returns the character "i" itself and turns that into a string instead of getting its actual value (number). The result of `.stringof` is implementation defined, it can be used for debugging but don't m

Re: How can overloads be distinguished on attributes alone?

2023-07-31 Thread Dennis via Digitalmars-d-learn
On Monday, 31 July 2023 at 16:09:11 UTC, bachmeier wrote: Is there a reason it would be difficult to make this not compile? No, except that might result in code breakage.

Re: How can overloads be distinguished on attributes alone?

2023-07-31 Thread Dennis via Digitalmars-d-learn
On Monday, 31 July 2023 at 10:55:44 UTC, Quirin Schroll wrote: What am I missing here? The duplicate definition check doesn't consider whether a function is actually unambiguously callable (without e.g. traits getOverloads), it only prevents creating the same linker symbol multiple time. So

Re: dub Fetches Wrong Package Version

2023-07-29 Thread Dennis via Digitalmars-d-learn
On Saturday, 29 July 2023 at 16:47:34 UTC, Ruby The Roobster wrote: Dub refuses to fetch the ~master branch of a package, even when dub.json tells it to. Is there any workaround to this? Delete dub.selections.json, which locks in dependency versions until you explicitly upgrade.

Re: Perspective Projection

2023-07-28 Thread Dennis via Digitalmars-d-learn
On Friday, 28 July 2023 at 16:08:43 UTC, Ruby The Roobster wrote: Everything displays fine (with orthographic projection, of course) if you leave the projection as the identity matrix, but setting it as I have done results in a blank screen. How do you pass the matrix to OpenGL? Be careful tha

Re: Syntax for Static Import of User Define Attributes

2023-07-28 Thread Dennis via Digitalmars-d-learn
On Friday, 28 July 2023 at 12:20:05 UTC, Steven Schveighoffer wrote: On 7/28/23 8:10 AM, Vijay Nayar wrote: It might be possible to expand the grammar. It seems very specific to UDAs, as it doesn't just throw out `Expression` or whatnot. It probably has to do with the spot that it's in (declar

Re: Syntax for Static Import of User Define Attributes

2023-07-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 July 2023 at 21:19:08 UTC, Vijay Nayar wrote: Attempted Fix 2: Enclose the entire attribute name in parenthesis. ``` static import vibe.data.serialization; class ChatCompletionFunctions { @(vibe.data.serialization.name)("name") ... } ``` Try: ```D @(vibe.data.serializatio

Re: AA vs __gshared

2023-07-27 Thread Dennis via Digitalmars-d-learn
On Thursday, 27 July 2023 at 15:57:51 UTC, IchorDev wrote: The faults happen seemingly at random, and from pretty mundane stuff like `if(auto x = y in z)` that run very often: Are you accessing the AA from multiple threads?

Re: Which D compiler is the most maintained and future-proof? [DMD GDC and LDC]

2023-07-24 Thread Dennis via Digitalmars-d-learn
On Monday, 24 July 2023 at 13:30:27 UTC, cc wrote: Is there any list of known significant "gotchas" with moving to LDC from DMD? Any unexpected surprises to watch out for or be careful for? - DMD has weak linking for all functions by default (mostly as a workaround to several bugs). In LDC,

Re: Print debug data

2023-07-20 Thread Dennis via Digitalmars-d-learn
On Wednesday, 19 July 2023 at 01:13:23 UTC, Steven Schveighoffer wrote: It's kind of a terrible message, I wish it would change to something more informative. As of https://github.com/dlang/dmd/pull/15430, there's a new message: ``` accessing non-static variable `freeSize` requires an instan

Re: getOverloads order

2023-07-13 Thread Dennis via Digitalmars-d-learn
On Thursday, 13 July 2023 at 11:04:40 UTC, IchorDev wrote: However, the spec doesn't specify that this is how `getOverloads` **must** work; is this guaranteed behaviour but the spec simply omits it? The order is not guaranteed. I don't know why you need a specific order, but perhaps you can s

Re: getOverloads order

2023-07-13 Thread Dennis via Digitalmars-d-learn
On Thursday, 13 July 2023 at 08:03:02 UTC, IchorDev wrote: I've noticed that `__traits(getOverloads)` always returns the overloads in lexical order across DMD, LDC, and GDC. Is this reliable at all? No. It depends on the order the compiler analyzes the symbols, which is often lexical order, b

Re: Strange behaviour of __traits(allMembers)

2023-06-28 Thread Dennis via Digitalmars-d-learn
On Sunday, 18 June 2023 at 10:21:16 UTC, IchorDev wrote: Whaat why has this not been fixed in the last 4 years! It's now fixed: https://github.com/dlang/dmd/pull/15335

Re: pragma msg field name?

2023-06-27 Thread Dennis via Digitalmars-d-learn
On Tuesday, 27 June 2023 at 05:03:01 UTC, Jonathan M Davis wrote: However, I would point out that getSymbolsByUDA gives you symbols, not strings, whereas pragma(msg, ...) wants a string. For some time now, it accepts any number of objects, which will all be converted to strings and concatenate

Re: Problem with dmd-2.104.0 -dip1000 & @safe

2023-06-10 Thread Dennis via Digitalmars-d-learn
On Friday, 9 June 2023 at 04:05:27 UTC, An Pham wrote: Getting with below error for following codes. Look like bug? Filed as https://issues.dlang.org/show_bug.cgi?id=23985 You can work around it by marking parameter `a` as `return scope`

Re: How to deal with interdependent dlang PRs?

2023-05-25 Thread Dennis via Digitalmars-d-learn
On Thursday, 25 May 2023 at 15:37:00 UTC, Quirin Schroll wrote: Is there a process? I can’t be the first one running into this. Doing it in 3 PRs is the process. This is one of the reasons why druntime was merged into dmd's repository. I remember someone saying that if you name the git branch

Re: cast expressions

2023-05-03 Thread Dennis via Digitalmars-d-learn
On Wednesday, 3 May 2023 at 09:03:38 UTC, Dom DiSc wrote: I know, (c) is a constructor call, but for basic types that's the same as (a) isn't it? No, a cast allows for overflow `cast(ubyte) 256`, while the constructor needs an integer that fits. `ubyte(256)` is an error. If t provides a cons

Re: -preview=in deprecation warning

2023-04-20 Thread Dennis via Digitalmars-d-learn
On Thursday, 20 April 2023 at 09:14:48 UTC, Jack Applegame wrote: Can anyone help me get rid of this depreciation? Annotate `getFoo` with `return scope`: ```d struct Foo { string foo; string getFoo() return scope const @safe { return foo; } }

Re: Returning a reference to be manipulated

2023-04-16 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 April 2023 at 21:00:01 UTC, kdevel wrote: On Saturday, 15 April 2023 at 15:50:18 UTC, Dennis wrote: [...] care about the type / mutability of the pointer. Returning `i`'s address in a long does not trigger the escape detector: It doesn't care about the type of pointer, but i

Re: Returning a reference to be manipulated

2023-04-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 April 2023 at 14:33:52 UTC, kdevel wrote: Does that make sense? Whether it makes sense is subjective, but it is by design. Escape analysis considers every pointer the same, it doesn't care about the type / mutability of the pointer. In `@system` / `@trusted` code, you could

Re: Returning a reference to be manipulated

2023-04-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 April 2023 at 14:10:57 UTC, Dennis wrote: This adds complexity, just to add some 'intermediate' safety between `@system` and `@safe` in a few cases. It's better to keep the rules simple and consistent. To quote my past self: There used to be different rules for lifetime error

Re: Returning a reference to be manipulated

2023-04-15 Thread Dennis via Digitalmars-d-learn
On Saturday, 15 April 2023 at 13:20:09 UTC, kdevel wrote: Under which circumstances is it a mistake to insert the `return` at the indicated position? If there are none why can't it be done implicitly (automatically)? It could be done in the easy example you posted, but generalizing it is hard

Re: Returning a reference to be manipulated

2023-04-14 Thread Dennis via Digitalmars-d-learn
On Friday, 14 April 2023 at 10:31:58 UTC, kdevel wrote: But in fact it is returned unless it is `return ref`. When using `return ref`, `return scope`, `scope` etc., you should be using the latest compiler and annotate functions you want checked with `@safe`. In previous versions, the compiler

Re: Is this code correct?

2023-04-01 Thread Dennis via Digitalmars-d-learn
On Friday, 31 March 2023 at 13:11:58 UTC, z wrote: I've tried to search before but was only able to find articles for 3D triangles, and documentation for OpenGL, which i don't use. The first function you posted takes a 3D triangle as input, so I assumed you're working in 3D. What are you work

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-03-31 Thread Dennis via Digitalmars-d-learn
On Friday, 31 March 2023 at 16:26:36 UTC, ryuukk_ wrote: That the same bad advice as telling people to "embrace OOP and multiple inheritance" and all the Java BS "just put your variable into a class and make it static, and then have your singleton to access your static variables" I agree tha

Re: Why are globals set to tls by default? and why is fast code ugly by default?

2023-03-31 Thread Dennis via Digitalmars-d-learn
On Friday, 31 March 2023 at 15:52:21 UTC, ryuukk_ wrote: the point i bring is ``__gshared`` is ugly, so we want an ugly language? Good code shouldn't look ugly, but global mutable variables are bad, so it's appropriate that they look ugly. You can still put a single `__gshared:` at the top o

Re: Is this code correct?

2023-03-30 Thread Dennis via Digitalmars-d-learn
On Thursday, 30 March 2023 at 10:29:25 UTC, z wrote: Is this code correct or logically sound? You need to be exact on what 'correct' is. The comment above `triangleFacesCamera` says: Indicates wether a triangle faces an imaginary view point. There's no view point / camera position defined

Re: The Phobos Put

2023-03-29 Thread Dennis via Digitalmars-d-learn
On Wednesday, 29 March 2023 at 11:10:42 UTC, Salih Dincer wrote: Why does my `put` work but the Phobos `put` doesn't work with a slice? Your `put` doesn't take `range` by `ref`, so it allows you to pass an rvalue. Consequently, it doesn't advance the range from the callers perspective.

Re: Problem with ImportC example?

2023-01-17 Thread Dennis via Digitalmars-d-learn
On Tuesday, 17 January 2023 at 11:16:25 UTC, DLearner wrote: ``` C:\Users\SoftDev\Documents\BDM\D\ImportC>dmd ex01.c ex01.c(1): Error: C preprocessor directive `#include` is not supported ex01.c(1): Error: no type for declarator before `#` ex01.c(5): Error: no type for declarator before `retur

Re: Unittests on a module

2023-01-13 Thread Dennis via Digitalmars-d-learn
On Friday, 13 January 2023 at 19:07:46 UTC, DLearner wrote: Is this intended? It is by design, though opinions differ on whether it's a good design. It's not a problem to add temporary ``` void main() { } ``` to the bottom of the module, You can add the `-main` flag to make dmd automatic

Re: Should importC fail on invalid C code?

2023-01-13 Thread Dennis via Digitalmars-d-learn
On Friday, 13 January 2023 at 12:50:44 UTC, kdevel wrote: Should importC fail on invalid C code? In general, no. The purpose is to build / interface with existing C code, not to develop new C code with it. ImportC also has its own extensions by borrowing D features such as __import, CTFE, an

Re: Why does the importC example not compile?

2023-01-13 Thread Dennis via Digitalmars-d-learn
On Friday, 13 January 2023 at 12:33:28 UTC, kdevel wrote: What must be added or changed in order to test every example which is intended to produce an executable? Support for separate compilation / ImportC would need to be added to dspec_tester: https://github.com/dlang/dlang.org/blob/master/

Re: Why does the importC example not compile?

2023-01-13 Thread Dennis via Digitalmars-d-learn
Thanks for reporting this. PR: https://github.com/dlang/dlang.org/pull/3489 On Friday, 13 January 2023 at 11:10:23 UTC, kdevel wrote: I would have expected that each and every piece of code in the documentation is automatically compiled with any new compiler release. Individual D snippets can

Re: How Can i see associative array implement , is where has pseudocode write in Dlang?

2022-12-29 Thread Dennis via Digitalmars-d-learn
On Thursday, 29 December 2022 at 11:24:38 UTC, lil wrote: How Can i see associative array implement , is where has pseudocode write in Dlang? If you're asking for the implementation of Associative Arrays, you can find that in druntime in the `rt.aaA` module: https://github.com/dlang/dmd/bl

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 "const"?](https://forum.dlang.org/post/dkkxcibwdsndbckon...@foru

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 MSVC

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 d

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 (e

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 `upb_MiniTabl

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 va

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 dmd

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 D,

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 turn

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 a

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 a

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 build]

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: https://iss

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` executabl

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

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 `immutable(char)[]`

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 th

  1   2   3   4   >