Re: LDC Internal Compiler Error (ICE) mentioning attribute 'nocapture'

2024-03-31 Thread Basile B. via Digitalmars-d-learn
On Saturday, 30 March 2024 at 09:35:24 UTC, Per Nordlöw wrote: Does anybody recognize the error ``` Attribute 'nocapture' does not apply to function return values %12 = call noalias nocapture align 8 ptr @_D3xxx(ptr nonnull %10, { i64, ptr } %11) #2, !dbg !7978 Attribute 'nocapture' does

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-14 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 March 2024 at 00:00:01 UTC, Richard (Rikki) Andrew Cattermole wrote: On 15/03/2024 12:47 PM, Basile B. wrote: On Thursday, 14 March 2024 at 23:39:33 UTC, Liam McGillivray wrote: On Thursday, 14 March 2024 at 01:58:46 UTC, Richard (Rikki) Andrew Cattermole wrote: [...] I tried

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-14 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 March 2024 at 23:39:33 UTC, Liam McGillivray wrote: On Thursday, 14 March 2024 at 01:58:46 UTC, Richard (Rikki) Andrew Cattermole wrote: [...] I tried to rework the functions to use bitwise operations, but it was difficult to figure out the correct logic. I decided that it's

Re: varargs when they're not all the same type?

2024-03-14 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 March 2024 at 20:58:21 UTC, Andy Valencia wrote: On Thursday, 14 March 2024 at 18:05:59 UTC, H. S. Teoh wrote: ... The best way to do multi-type varags in D is to use templates: import std; void myFunc(Args...)(Args args) { Thank you. The first parenthetical

Re: Challenge: Make a data type for holding one of 8 directions allowing increment and overflow

2024-03-13 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 12 March 2024 at 05:38:03 UTC, Liam McGillivray wrote: I am in need of a data type for holding direction information; one of 8 directions on a single axis. They are named in terms of compass directions. If D had a 4-bit datatype, I would just use this and do `+=2` whenever I want

Re: what was the problem with the old post blit operator already ?

2024-02-14 Thread Basile B. via Digitalmars-d-learn
On Thursday, 15 February 2024 at 03:17:11 UTC, Jonathan M Davis wrote: On Wednesday, February 14, 2024 7:17:15 PM MST Basile B. via Digitalmars-d- learn wrote: From what I remember, it was that there was no reference to the source. Things got blitted and you had to fix the copy, already

Re: Safety is not what you think

2024-02-05 Thread Basile B. via Digitalmars-d-learn
On Monday, 5 February 2024 at 14:26:45 UTC, Basile B. wrote: On Tuesday, 30 January 2024 at 15:38:26 UTC, Paul Backus wrote: [...] This definitely isn't allowed in C or C++. I wonder what the rationale is for having this behavior in D? [1]: https://dlang.org/spec/expression.html An

Re: Safety is not what you think

2024-02-05 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 30 January 2024 at 15:38:26 UTC, Paul Backus wrote: [...] This definitely isn't allowed in C or C++. I wonder what the rationale is for having this behavior in D? [1]: https://dlang.org/spec/expression.html An hypothesis is that this makes codegening the pre and the post

Re: Checking path name

2023-12-14 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 December 2023 at 03:58:37 UTC, Joel wrote: If I get user input, for example, how do I check to see if it's a valid path, like, file name. ```d // something like this: if (getUserInput.isValidPath) { ... } ``` https://dlang.org/phobos/std_file.html#exists

Re: question

2023-12-13 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 13 December 2023 at 12:49:14 UTC, fred wrote: [...] a bug ? thanks anyway Try to define the flag as static ```d static shared(bool) isDone = false; ``` I dont know if that should be a compiler error to have local shared (I tend to think yes as locals are specific to a frame,

Re: mixin under -betterC

2023-11-26 Thread Basile B. via Digitalmars-d-learn
On Thursday, 23 November 2023 at 16:33:52 UTC, DLearner wrote: Code below is intended to test simple mixin with lambda function under -betterC. Works with full-D, but fails with 'needs GC' errors under -betterC. Why is this so, bearing in mind the concatenations are executed at compile, not

Re: Why can't we use strings in C++ methods?

2023-11-04 Thread Basile B. via Digitalmars-d-learn
On Saturday, 4 November 2023 at 13:51:20 UTC, Dadoum wrote: On Saturday, 4 November 2023 at 13:45:56 UTC, Emmanuel Danso Nyarko wrote: [...] There is a syntax disagreement here that's why the D compiler is instantly stopping you from doing any symbol generated interaction with string in C++

Re: Function Overloading

2023-11-02 Thread Basile B. via Digitalmars-d-learn
On Thursday, 2 November 2023 at 11:17:42 UTC, Salih Dincer wrote: On Wednesday, 1 November 2023 at 20:04:52 UTC, Basile B. wrote: Yes. D constructors are not named but the current implementation adds a name that is `__ctor`, so add ```d alias add = __ctor; ``` to you struct. Yeah, it

Re: Function Overloading

2023-11-01 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 31 October 2023 at 20:09:44 UTC, Salih Dincer wrote: [...] is it possible to do something like `alias add = this;`? ```d struct Calculate {   int memory; string result;    auto toString() => result;    // alias add = this;     import std.string : format;    

Re: How to use core.vararg to print D variadic arguments and their types without using ! (template instantiation)?

2023-09-15 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 September 2023 at 15:19:29 UTC, BoQsc wrote: https://dlang.org/phobos/core_vararg.html The common way to use **va_arg** is `va_arg!(int)(_argptr);` What would be the alternative way or syntax that behave exactly the same way, even if more verbose?

Re: Weird floating point rounding - Bug or how to control it correctly

2023-09-13 Thread Basile B. via Digitalmars-d-learn
On Thursday, 14 September 2023 at 03:23:48 UTC, An Pham wrote: import std.stdio; void main() { float f = 6394763.345f; import std.format : sformat; char[80] vBuffer = void; writeln("6394763.345 = ", sformat(vBuffer[], "%.4f", f));

Re: malloc error when trying to assign the returned pointer to a struct field

2023-09-08 Thread Basile B. via Digitalmars-d-learn
On Friday, 8 September 2023 at 19:14:47 UTC, H. S. Teoh wrote: [...] My guess is that you have a double-free somewhere, or there's a buffer overrun. Or maybe some bad interaction with the GC, e.g. if you tried to free a pointer from the GC heap. That cant be a GC problem as rempas project is

Re: malloc error when trying to assign the returned pointer to a struct field

2023-09-08 Thread Basile B. via Digitalmars-d-learn
On Friday, 8 September 2023 at 18:59:21 UTC, rempas wrote: On Friday, 8 September 2023 at 16:02:36 UTC, Basile B. wrote: Could this be a problem of copy construction ? I don't think so. My idea was that if you dont have defined a copy constructor and if an instance is assigned to another,

Re: malloc error when trying to assign the returned pointer to a struct field

2023-09-08 Thread Basile B. via Digitalmars-d-learn
On Friday, 8 September 2023 at 07:59:37 UTC, rempas wrote: I do have the following struct: [...] Is there any possible that there is a compiler bug? I do use ldc2 and `betterC`! Could this be a problem of copy construction ?

Re: Pointer to environment.get

2023-08-28 Thread Basile B. via Digitalmars-d-learn
On Monday, 28 August 2023 at 10:20:14 UTC, Basile B. wrote: On Monday, 28 August 2023 at 06:38:50 UTC, Vino wrote: Hi All, The the below code is not working, hence requesting your help. Code: ``` import std.stdio; import std.process: environment; void main () { int* ext(string) =

Re: Pointer to environment.get

2023-08-28 Thread Basile B. via Digitalmars-d-learn
On Monday, 28 August 2023 at 06:38:50 UTC, Vino wrote: Hi All, The the below code is not working, hence requesting your help. Code: ``` import std.stdio; import std.process: environment; void main () { int* ext(string) = ("PATHEXT"); writeln(*ext); } ``` Problems is that "PATHEXT" is

Re: Adding to a global AliasSeq

2023-08-18 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 15 August 2023 at 12:20:54 UTC, repr_man wrote: On Tuesday, 15 August 2023 at 07:02:45 UTC, Basile B. wrote: You can add a kind of tag with the mixin, that will allow to to test if the type supplied to `f` is well a Base implementor: Firstly, thank you for your help. This is

Re: Adding to a global AliasSeq

2023-08-15 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 15 August 2023 at 02:30:37 UTC, repr_man wrote: Consider the following template mixin: ```d mixin template Base() { int x(){ return 10; } } ``` It could be used in a variety of structs as follows: ```d struct Child { mixin Base!(); } ``` Now, let's suppose we write a function

Re: Compiler interoperability

2023-07-07 Thread Basile B. via Digitalmars-d-learn
On Friday, 7 July 2023 at 08:19:28 UTC, Chris Katko wrote: For a specific system (Linux, e.g): What is the level of interoperability between the different D compilers; DMD, LDC, and GDC? It appears each one has different benefits, and, different experimental features. Link-time optimization

Re: key membership in multi-dimensional assoc. array

2023-06-14 Thread Basile B. via Digitalmars-d-learn
On Thursday, 15 June 2023 at 01:47:45 UTC, Paul wrote: I found I can check for key membership in a multi-D aa... ```d byte zKey = someval; byte[byte][byte][byte] cubelist; foreach(byte xK, yzcubelist; cubelist) { foreach(byte yK, zcubelist; yzcubelist) { foreach(byte zK, val; zcubelist) {

Re: assert/static assert message format difference

2023-06-13 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 13 June 2023 at 16:46:26 UTC, DLearner wrote: Only a small thing, but is it intended that: ``` void main() { // static assert (false, "Static Assert triggered"); assert(false, "Assert triggered"); } ``` produces ``` core.exception.AssertError@staticassertex01.d(4): Assert

Re: byte and short data types use cases

2023-06-09 Thread Basile B. via Digitalmars-d-learn
On Friday, 9 June 2023 at 15:07:54 UTC, Murloc wrote: On Friday, 9 June 2023 at 12:56:20 UTC, Cecil Ward wrote: On Friday, 9 June 2023 at 11:24:38 UTC, Murloc wrote: If you have four ubyte variables in a struct and then an array of them, then you are getting optimal memory usage. Is this

Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-06 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 6 June 2023 at 14:23:59 UTC, Steven Schveighoffer wrote: On 6/5/23 11:33 AM, Basile B. wrote: [...] Ugh, don't do it that way. Always give opDispatch a template constraint or it will suck to use. Also, given the problem constraints, you can build the method automatically using

Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-06 Thread Basile B. via Digitalmars-d-learn
On Monday, 5 June 2023 at 15:28:34 UTC, Paul Backus wrote: Is there a reason you can't just make these fields `public`? My bet is that OP actually wants to generate something like ```d void setStrokeWidth(uint value) { if (value = strokeWidth) return; strokeWidth = value;

Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-06 Thread Basile B. via Digitalmars-d-learn
On Monday, 5 June 2023 at 15:28:34 UTC, Paul Backus wrote: Is there a reason you can't just make these fields `public`? My bet is that OP actually wants to generate something like ```d void setStrokeWidth(uint value) { if (value = strokeWidth) return; strokeWidth = value;

Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-05 Thread Basile B. via Digitalmars-d-learn
On Monday, 5 June 2023 at 15:13:43 UTC, Basile B. wrote: On Monday, 5 June 2023 at 13:57:20 UTC, Ki Rill wrote: How do I generate `setX` methods for all private mutable although I did not spent time on the setter body... I suppose the question was more about the metprogramming technic, and

Re: How do I generate `setX` methods for all private mutable variables in a class?

2023-06-05 Thread Basile B. via Digitalmars-d-learn
On Monday, 5 June 2023 at 13:57:20 UTC, Ki Rill wrote: How do I generate `setX` methods for all private mutable variables in my class? Do I need to use `__traits`? I need this for my [tiny-svg](https://github.com/rillki/tiny-svg) project to generate `setX` methods for all Shapes. Example:

Re: Concepts like c++20 with specialized overload resolution.

2023-05-27 Thread Basile B. via Digitalmars-d-learn
On Saturday, 27 May 2023 at 13:23:38 UTC, vushu wrote: [...] Is there something equivalent in dlang, doesn't seem like d support specialized overload? D solution is called [template constraints](https://dlang.org/spec/template.html#template_constraints).

Re: Multiple destructors

2023-05-26 Thread Basile B. via Digitalmars-d-learn
On Friday, 26 May 2023 at 09:07:07 UTC, Alex Biscotti wrote: Hello everyone! While researching the phobos library, I discovered that a class can have multiple destructors if the destructors are added via mixin injection. Accordingly, the question is whether a description of such feature should

Re: D style - member functions

2023-04-26 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 26 April 2023 at 18:24:08 UTC, DLearner wrote: Consider: ``` struct S1 { int A; int B; int foo() { return(A+B); } } struct S2 { int A; int B; } int fnAddS2(S2 X) { return (X.A + X.B); } void main() { import std.stdio : writeln; S1 Var1 = S1(1,

Re: alias Error: need 'this'

2023-03-19 Thread Basile B. via Digitalmars-d-learn
On Sunday, 19 March 2023 at 13:49:36 UTC, bomat wrote: Thanks for the suggested workaround, I can live with the `static` solution, I guess. I still don't understand why it's necessary, though. Since a `struct` is a value type and, as I understand it, stack allocated, what difference does it

Re: Difference between using `import` with/without the colon

2023-03-19 Thread Basile B. via Digitalmars-d-learn
On Sunday, 19 March 2023 at 07:20:17 UTC, Jeremy wrote: Hello, is there any difference at all between the following lines, as an example: ```d import std.regex; import std.regex : matchFirst; ``` What technical differences does it make (except for having the identifier available), using the

Re: const in functions

2023-03-13 Thread Basile B. via Digitalmars-d-learn
On Sunday, 12 March 2023 at 15:09:45 UTC, Salih Dincer wrote: Hi, [...] // A, we can get its to guarantee us that parameters // won't change: auto inConst(T)(T a, const T b) // const { // it's not needed --^ but ^-- why can't this be used Well you got the great answers to your

Re: Using Windbg to debug D applications and unittests

2023-03-05 Thread Basile B. via Digitalmars-d-learn
On Saturday, 4 March 2023 at 19:19:26 UTC, Chris Piker wrote: On Monday, 27 February 2023 at 12:09:50 UTC, Basile B. wrote: At least this is what is done for the Dexed GDB widget, so that gdb breaks automatically when an Error or an Exception is new'd

Re: Using Windbg to debug D applications and unittests

2023-02-27 Thread Basile B. via Digitalmars-d-learn
On Saturday, 25 February 2023 at 15:55:33 UTC, solidstate1991 wrote: I had a lot of trouble trying to get Visual Studio to catch handled exceptions, which would have been mandatory for debugging unittests, but I either forgot how to do it, or something have changed in either the newer versions

Re: What is the 'Result' type even for?

2023-01-19 Thread Basile B. via Digitalmars-d-learn
On Friday, 20 January 2023 at 03:11:33 UTC, Ruby The Roobster wrote: Take this example: [...] What is the purpose of this 'Result' type? To serve as a generic range? Yes this is a lazy input range. Use `.array` to yield directly as a concrete value, then you can append using `~=`. Note

Re: Is there a formula for overflow?

2022-11-29 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:19:49 UTC, Basile B. wrote: [...] It's always a wraparound (think modulo) but your examples with negative number can be explained because there are hidden unsigned to signed implicit convertions. That the only special things D does. forgot to say, you

Re: Is there a formula for overflow?

2022-11-29 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 30 November 2022 at 03:07:44 UTC, thebluepandabear wrote: I am reading through Ali's book about D, and he gives the following examples for an overflow: ```D import std.stdio; void main() { // 3 billion each uint number_1 = 30; uint number_2 = 30; }

Re: Thinking about the difference between fixed and 'dynamic' arrays.

2022-11-29 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 29 November 2022 at 18:59:46 UTC, DLearner wrote: To me, it appears that there are really two (_entirely separate_) concepts: A. Supporting the useful concept of variable length (but otherwise entirely conventional) arrays; B. Supporting a language feature that acts as a window to

Re: What exact debugging information is added to the binary and how to parse it all?

2022-05-13 Thread Basile B. via Digitalmars-d-learn
On Friday, 13 May 2022 at 16:11:14 UTC, BoQsc wrote: Haven't used debuggers or debugged a lot just yet, but I've had this question in my mind and I'd like to inspect some debugging information manually. Are there some kind of documentation or specification and are there a lot of information

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Basile B. via Digitalmars-d-learn
On Thursday, 12 May 2022 at 15:31:03 UTC, Steven Schveighoffer wrote: On 5/12/22 11:18 AM, jmh530 wrote: On Thursday, 12 May 2022 at 12:13:32 UTC, Basile B. wrote: [snip] ``` is ( Type : TypeSpecialization , TemplateParameterList ) is ( Type == TypeSpecialization , TemplateParameterList ) is (

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Basile B. via Digitalmars-d-learn
On Thursday, 12 May 2022 at 14:06:13 UTC, Arjan wrote: On Thursday, 12 May 2022 at 11:05:08 UTC, Basile B. wrote: On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: - Operator overloading in certain cases was confusing, I remember that for one particular form once I had to use your

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Basile B. via Digitalmars-d-learn
On Thursday, 12 May 2022 at 12:13:32 UTC, Basile B. wrote: On Thursday, 12 May 2022 at 11:50:59 UTC, Alain De Vos wrote: Some keywords are overloaded and have different meaning when used in a different place. Also some syntactic-sugar is way to much meaning too many different ways to do the

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Basile B. via Digitalmars-d-learn
On Thursday, 12 May 2022 at 11:50:59 UTC, Alain De Vos wrote: Some keywords are overloaded and have different meaning when used in a different place. Also some syntactic-sugar is way to much meaning too many different ways to do the same thing. I would prefer one way which is advised. `ptr1

Re: What are (were) the most difficult parts of D?

2022-05-12 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 11 May 2022 at 05:41:35 UTC, Ali Çehreli wrote: What are you stuck at? What was the most difficult features to understand? etc. To make it more meaningful, what is your experience with other languages? Ali Overhall I think that D was not hard to learn because well designed

Re: Trait for "can be instantiated"?

2022-05-11 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 10 May 2022 at 16:10:26 UTC, Ben Jones wrote: On Tuesday, 10 May 2022 at 16:05:15 UTC, H. S. Teoh wrote: Using wrapper structs, etc., for this is IMO total overkill. Just use an enum for your token types. Something like this would suffice: That's basically what sumtype is going

Re: Make shared static this() encoding table compilable

2022-03-14 Thread Basile B. via Digitalmars-d-learn
On Monday, 14 March 2022 at 09:40:00 UTC, zhad3 wrote: Hey everyone, I am in need of some help. I have written this Windows CP949 encoding table https://github.com/zhad3/zencoding/blob/main/windows949/source/zencoding/windows949/table.d which is used to convert CP949 to UTF-16. After some

Re: Detecting manifest contants

2022-03-13 Thread Basile B. via Digitalmars-d-learn
On Saturday, 12 March 2022 at 18:49:32 UTC, Anonymouse wrote: I'm introspecting structs, and I ran into an issue where `__traits(derivedMembers)` includes manifest constant enums in the returned tuple. What is the correct way to statically detect these? The immediate thing that springs to

Re: https://run.dlang.io/ vs All dmd compilers (2.060 - latest)

2022-02-28 Thread Basile B. via Digitalmars-d-learn
On Sunday, 27 February 2022 at 16:14:31 UTC, Matheus wrote: Hi, [...] After one minute I think I get: rdmd playground.d Server error: Thanks, Matheus. This was [reported before]. Apparently this would be caused by a timeout. [reported before]:

Re: Set output location for dub --single

2022-02-28 Thread Basile B. via Digitalmars-d-learn
On Sunday, 27 February 2022 at 16:58:34 UTC, Chris Piker wrote: Hi D Coming from a python background it's worked well to organize my D projects as a dub `sourceLibrary` and then to put top level programs in a directory named `scripts` that are just dub single file projects. So the layout

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:12:38 UTC, partypooper wrote: On Monday, 21 February 2022 at 11:07:55 UTC, Basile B. wrote: Yeah there must be another one then. Something actionnable is the documentation. What about Mike Parker answer? if nothrow fails that's because things are checked.

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 11:05:42 UTC, partypooper wrote: On Monday, 21 February 2022 at 10:58:26 UTC, Basile B. wrote: more likely UTFException actually Additionaly catching UTF and Conv exceptions doesn't help. Yeah there must be another one then. Something actionnable is the

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() { try { writeln("Hello, World!") } catch (StdioException)

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:53:56 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() {

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:53:56 UTC, Basile B. wrote: On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() {

Re: Why writeln can't be converted to nothrow with just catching of StdioException

2022-02-21 Thread Basile B. via Digitalmars-d-learn
On Monday, 21 February 2022 at 10:49:13 UTC, partypooper wrote: Do I completely not understand what is `nothrow` or why I can't make function nothrow with just catching StdioException? This doesn't work ```d nothrow void hello() { try { writeln("Hello, World!") } catch (StdioException)

Re: keyword as struct field

2022-02-20 Thread Basile B. via Digitalmars-d-learn
On Sunday, 20 February 2022 at 11:08:55 UTC, partypooper wrote: Hello, I'm new to D. Title is self described, is it possible to use keyword as struct field? Maybe it is XYproblem, so here I will describe a little what I need. I'm parsing some json currently with

Re: Declaring a reusable formula and using it in other scopes.

2022-02-12 Thread Basile B. via Digitalmars-d-learn
On Saturday, 12 February 2022 at 12:36:06 UTC, BoQsc wrote: `bool nextArgumentDoesNotReachEndOfArray = i + 1 < args.length;` How can I declare it out of scope and reuse it in any scope that has `i` and `args.length` declared? Here is an ugly solution, just to encourage someone else to post

Re: Is there an equivavlent to C# boxing in D?

2022-02-12 Thread Basile B. via Digitalmars-d-learn
On Saturday, 12 February 2022 at 16:50:16 UTC, H. S. Teoh wrote: Without alias this it would be harder to pull off, yes. I don't see any other way that allows to unbox *implictly*. That would require a new operator. Something like opCast but more permissive, that works without `cast`.

Re: ldc executable crashes with this code

2022-02-02 Thread Basile B. via Digitalmars-d-learn
On Thursday, 3 February 2022 at 01:51:34 UTC, Basile B. wrote: On Thursday, 3 February 2022 at 01:39:33 UTC, forkit wrote: On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote: [...] that explains ldc perhaps (although i don't really get it. It's cast to mutable and being

Re: ldc executable crashes with this code

2022-02-02 Thread Basile B. via Digitalmars-d-learn
On Thursday, 3 February 2022 at 01:39:33 UTC, forkit wrote: On Wednesday, 2 February 2022 at 23:30:50 UTC, H. S. Teoh wrote: [...] that explains ldc perhaps (although i don't really get it. It's cast to mutable and being assigned to mutable. in any case... ldc doesn't like it, but dmd is

Re: Is DMD still not inlining "inline asm"?

2021-11-13 Thread Basile B. via Digitalmars-d-learn
On Friday, 12 November 2021 at 00:46:05 UTC, Elronnd wrote: On Thursday, 11 November 2021 at 13:22:15 UTC, Basile B. wrote: As for now, I know no compiler that can do that. GCC can do it. Somewhat notoriously, you meant "infamously" ? LTO can lead to bugs from underspecified asm

Re: Is DMD still not inlining "inline asm"?

2021-11-11 Thread Basile B. via Digitalmars-d-learn
On Thursday, 11 November 2021 at 08:58:43 UTC, rempas wrote: I've seen from [this](https://forum.dlang.org/post/op.vrzngqeavxi10f@biotronic-laptop) reply in a thread from 2011 that DMD will not inline functions that contain inline assembly. Is this still the case? Yes, this is still the case.

Re: Possible runtime bug in preprocessing of command line arguments passed to the D main

2021-10-24 Thread Basile B. via Digitalmars-d-learn
On Sunday, 24 October 2021 at 14:38:44 UTC, jfondren wrote: [...] With nothing to the contrary, I'd take "must be terminated by a null pointer" as "can't itself be a null pointer". ah yeah, and thanks, of course ... how would the count of arg be known without the sentinel...

Re: Possible runtime bug in preprocessing of command line arguments passed to the D main

2021-10-24 Thread Basile B. via Digitalmars-d-learn
On Sunday, 24 October 2021 at 14:21:52 UTC, Basile B. wrote: The following code, on linux [...] What do you think ? Forgot to say that this change ```diff - execv("a", null); + execv("a", ["whatever".ptr].ptr); ``` makes the problem goes away, so it would be caused by how `null` args are

Possible runtime bug in preprocessing of command line arguments passed to the D main

2021-10-24 Thread Basile B. via Digitalmars-d-learn
The following code, on linux ```d module runnable; ​ extern(C) int execv(const char* p, const char** args); ​ immutable src = ` import std.getopt; void main(string[] args) { bool c; getopt(args, "c", ); } `; ​ void prepareProgram() { import std.process :

Re: How to make a function that accepts optional struct but can accept struct literal too

2021-10-16 Thread Basile B. via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:33:33 UTC, JN wrote: Is there some nice way of achieving something like this C99 code in D? [...] The [literal](https://www.ibm.com/docs/sr/xl-c-and-cpp-aix/13.1.0?topic=operators-compound-literal-expressions) in the C version creates an alloca too but it's

Re: Better debugging?

2021-10-03 Thread Basile B. via Digitalmars-d-learn
On Sunday, 3 October 2021 at 22:21:45 UTC, Tim wrote: Hi all, I am currently using GDB within VScode with the -gc DMD2 compiler switch and my debugging is not amazing. Whenever I inspect a struct/object it just shows me the pointer rather than the object information and strings come up as a

Re: Mutually recursive template expansion

2021-10-02 Thread Basile B. via Digitalmars-d-learn
On Saturday, 2 October 2021 at 08:48:24 UTC, Stephen wrote: Is this by design? No but it's easily explainable. ## without mixins ```d struct Ar { Br b; ubyte a; } struct Br { ubyte b; } ``` `Ar` semantic starts, members are analyzed, that begins with the variable declaration `Br b`. `Br`

Re: 0 cost template instantiation

2021-09-29 Thread Basile B. via Digitalmars-d-learn
On Thursday, 30 September 2021 at 02:02:19 UTC, Hipreme wrote: On Thursday, 30 September 2021 at 01:56:42 UTC, Basile B. wrote: On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name:

Re: 0 cost template instantiation

2021-09-29 Thread Basile B. via Digitalmars-d-learn
On Thursday, 30 September 2021 at 01:09:47 UTC, Hipreme wrote: I have a template function that all it does is given a symbol, it loads a dll for its type + its name: ``` void loadSymbol(alias s, string symName = "")() { static if(symName == "") s =

Re: Which operators cannot be overloaded and why not?

2021-09-13 Thread Basile B. via Digitalmars-d-learn
On Monday, 13 September 2021 at 14:42:42 UTC, jfondren wrote: On Monday, 13 September 2021 at 14:33:03 UTC, user1234 wrote: - condition al expression ` cond ? exp : exp ` And many other boolean operators, unary !, binary && and || https://dlang.org/spec/operatoroverloading.html lists all the

Re: GDC - program runs in one thread, DMD - in 4 threads, why?

2021-09-10 Thread Basile B. via Digitalmars-d-learn
On Friday, 10 September 2021 at 09:27:49 UTC, eugene wrote: Here is test program (which is using DList aggressively) [...] Can this (really unwanted) behavior be disabled in DMD? I do not want to have multiple threads, a program (real program, not the test above) has to be single-threaded.

Re: Absence of isAllocator trait

2021-09-06 Thread Basile B. via Digitalmars-d-learn
On Saturday, 4 September 2021 at 19:43:27 UTC, Per Nordlöw wrote: Is there a reason for the absence of an `isAllocator` trait under `std.experimental.allocator`? I had ask a similar Q once and I've been told that (more or less): It's because the clients of an allocator should rather

Re: issue with static foreach

2021-07-22 Thread Basile B. via Digitalmars-d-learn
On Thursday, 22 July 2021 at 05:57:02 UTC, jfondren wrote: On Thursday, 22 July 2021 at 03:43:44 UTC, someone wrote: ... it compiles no-more: Error: found `End of File` when expecting `}` following compound statement ... what I am doing wrong ? You'll get the same error from this code:

Re: LLVM asm with constraints, and 2 operands

2021-07-19 Thread Basile B. via Digitalmars-d-learn
On Monday, 19 July 2021 at 10:21:58 UTC, kinke wrote: On Sunday, 18 July 2021 at 16:32:46 UTC, Basile B. wrote: - **=x** says "returns in whatever is has to" - **x** (1) is the constraint for input `a`, which is passed as operand **$0** - **x** (2) is the constraint for input `b`, which is

Re: LLVM asm with constraints, and 2 operands

2021-07-18 Thread Basile B. via Digitalmars-d-learn
On Sunday, 18 July 2021 at 17:45:05 UTC, Guillaume Piolat wrote: On Sunday, 18 July 2021 at 16:32:46 UTC, Basile B. wrote: [...] Thanks. Indeed that seems to work even when inline and optimized. Registers are spilled to stack. A minor concern is what happens when the enclosing function is

Re: LLVM asm with constraints, and 2 operands

2021-07-18 Thread Basile B. via Digitalmars-d-learn
On Sunday, 18 July 2021 at 18:47:50 UTC, Basile B. wrote: On Sunday, 18 July 2021 at 17:45:05 UTC, Guillaume Piolat wrote: On Sunday, 18 July 2021 at 16:32:46 UTC, Basile B. wrote: [...] Thanks. Indeed that seems to work even when inline and optimized. Registers are spilled to stack. A

Re: LLVM asm with constraints, and 2 operands

2021-07-18 Thread Basile B. via Digitalmars-d-learn
On Sunday, 18 July 2021 at 11:42:24 UTC, Guillaume Piolat wrote: Is anyone versed in LLVM inline asm? I know how to generate SIMD unary op with: return __asm!int4("pmovsxwd $1,$0","=x,x",a); but I struggle to generate 2-operands SIMD ops like: return __asm!int4("paddd

Re: Faster Dlang Execution

2021-06-08 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 8 June 2021 at 17:10:47 UTC, seany wrote: Hello How can I increase the speed of executable files created via : `dub build -b release` try `dub build -b release --compiler=ldc2` Then you can set some specific DFlags for ldc, like -O3 or --mcpu I am unable to parallellise all of

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

2021-05-27 Thread Basile B. via Digitalmars-d-learn
On Thursday, 27 May 2021 at 08:47:50 UTC, Tariq Siddiqui wrote: When using Compiler Explorer (https://godbolt.org/) to compare assembly output of simple programs, why D language assembly output is so long compared to C or C++ output. The simple square function output is the same for C, C++,

Re: cannot I override and mark it as private?

2021-05-12 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 12 May 2021 at 19:35:31 UTC, Jack wrote: I'd to change the visibility of a method overrided from public to private but it doesn't work tho to protected it does. Why is that? ... Why is that? why must I leave it accessible somehow (even if it's protected) to all derived class of

Re: alias & local function

2021-05-09 Thread Basile B. via Digitalmars-d-learn
On Monday, 10 May 2021 at 01:25:10 UTC, Alain De Vos wrote: This does not: ``` import std.stdio; void main() { int afunction(int x){return x;}; it's not static so -> context -> delegate alias myint = int; myint i=5;

Re: class grammar

2021-05-07 Thread Basile B. via Digitalmars-d-learn
On Friday, 7 May 2021 at 18:07:45 UTC, Nick wrote: The class grammar, as defined in the D language specification ... is not clear to me how a user-defined type (such as a class or interface) is also a 'BasicType' (as defined by the grammar). However, the compiler only accepts classes or

Re: Since dmd 2.096.0: import `x.t` is used as a type

2021-05-02 Thread Basile B. via Digitalmars-d-learn
On Sunday, 2 May 2021 at 15:41:13 UTC, kdevel wrote: On Saturday, 1 May 2021 at 16:32:32 UTC, Basile B. wrote: Hard breakage is not acceptable, even if the goal is to introduce a more correct behavior. I still wonder why module names are taken as a candidates for types and functions in the

Re: Fake IFTI-compatible struct constructors

2021-05-01 Thread Basile B. via Digitalmars-d-learn
On Saturday, 1 May 2021 at 21:57:54 UTC, Chad Joan wrote: I came up with a couple techniques for making it seem like templated structs deduce their template parameters from constructor invocations. These are given further down in the post. ... However, this was not to be. Rather, this setup

Re: Since dmd 2.096.0: import `x.t` is used as a type

2021-05-01 Thread Basile B. via Digitalmars-d-learn
On Friday, 30 April 2021 at 21:41:43 UTC, kdevel wrote: On Friday, 30 April 2021 at 19:17:14 UTC, user1234 wrote: [...] Likely a side effect of https://github.com/dlang/dmd/pull/12178 but according to me the new behavior is correct. It breaks my code. I have files named $C containing struct

Re: Derived type

2021-03-31 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 31 March 2021 at 04:49:50 UTC, novice3 wrote: On Tuesday, 30 March 2021 at 21:53:34 UTC, Basile B. wrote: struct Typedef(TBase) { TBase payload; alias payload this; } alias Xobj = Typedef!(void*); This is how std.typecons.Typedef made, IMHO. The problem is this code

Re: Derived type

2021-03-30 Thread Basile B. via Digitalmars-d-learn
On Tuesday, 30 March 2021 at 19:47:41 UTC, novice2 wrote: My tries to make template for struct and alias this: // variant 1 template Typedef(alias Tnew, Tbase) { struct Tnew { Tbase payload; alias payload this; } } you must give a name to the template specialization, using

Re: Using onOutOfMemoryError in C wrappers

2021-03-24 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 24 March 2021 at 08:51:34 UTC, Per Nordlöw wrote: On Wednesday, 24 March 2021 at 08:31:19 UTC, Basile B. wrote: There are several ways to do that. In addition to onOutOfMemoryError, you can use a static instance void v() @nogc nothrow { __gshared oom = new

Re: Using onOutOfMemoryError in C wrappers

2021-03-24 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 24 March 2021 at 07:58:22 UTC, Per Nordlöw wrote: When wrapping C code that tries to allocate memory resources via functions such as X* X_create(); should one call `onOutOfMemoryError();` upon null return? Making more D wrappers `nothrow @nogc`. There are several ways to

Re: Checking for manifest constants

2021-03-05 Thread Basile B. via Digitalmars-d-learn
On Friday, 5 March 2021 at 08:23:09 UTC, Bogdan wrote: I was using a trick with dmd to check for manifest constants which worked until dmd v2.094. Yesterday I tried it on the latest compiler and it failed with: source/introspection/manifestConstant.d(37,28): Error: need this for name of

Re: Dimensions in compile time

2021-02-08 Thread Basile B. via Digitalmars-d-learn
On Monday, 8 February 2021 at 13:27:14 UTC, Vindex wrote: Thanks everyone! The solution that works for me now looks like this: template ndim(T) { static if (std.traits.isArray!T) { static if (is(typeof(T.init[0]))) { alias SubArrayType = typeof(T.init[0]);

Re: Dimensions in compile time

2021-02-08 Thread Basile B. via Digitalmars-d-learn
On Monday, 8 February 2021 at 13:13:33 UTC, Basile B. wrote: On Monday, 8 February 2021 at 13:09:53 UTC, Rumbu wrote: On Monday, 8 February 2021 at 12:19:26 UTC, Basile B. wrote: [...] dimensionCount!string should be 2. My take without std.traits: template rank(T: U[], U) { enum rank =

Re: Dimensions in compile time

2021-02-08 Thread Basile B. via Digitalmars-d-learn
On Monday, 8 February 2021 at 13:09:53 UTC, Rumbu wrote: On Monday, 8 February 2021 at 12:19:26 UTC, Basile B. wrote: [...] dimensionCount!string should be 2. My take without std.traits: template rank(T: U[], U) { enum rank = 1 + rank!U; } template rank(T: U[n], size_t n) { enum

  1   2   3   4   5   6   7   8   >