Re: Pointer to dlang spec for this alias construct?

2024-06-17 Thread Andy Valencia via Digitalmars-d-learn
On Monday, 17 June 2024 at 05:05:06 UTC, Jonathan M Davis wrote: alias Unshared(T) = T; alias Unshared(T: shared U, U) = U; ... Unshared is an eponymous template. https://dlang.org/spec/template.html#implicit_template_properties And it's using a shortcut syntax. ... The second

Re: Pointer to dlang spec for this alias construct?

2024-06-16 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, June 16, 2024 10:32:50 PM MDT Andy Valencia via Digitalmars-d-learn wrote: > In the alias: > > alias Unshared(T) = T; > alias Unshared(T: shared U, U) = U; > > as used in: > > cast(Unshared!mytype)value > > turns a mytype with shared attribute into one without shared. >

Re: Pointer to dlang spec for this alias construct?

2024-06-16 Thread evilrat via Digitalmars-d-learn
On Monday, 17 June 2024 at 04:32:50 UTC, Andy Valencia wrote: In the alias: alias Unshared(T) = T; alias Unshared(T: shared U, U) = U; as used in: cast(Unshared!mytype)value turns a mytype with shared attribute into one without shared. I deduce the alias is using some sort of

Pointer to dlang spec for this alias construct?

2024-06-16 Thread Andy Valencia via Digitalmars-d-learn
In the alias: alias Unshared(T) = T; alias Unshared(T: shared U, U) = U; as used in: cast(Unshared!mytype)value turns a mytype with shared attribute into one without shared. I deduce the alias is using some sort of type matching and decomposition? I've read through the

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-10 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 10 May 2024 at 16:33:53 UTC, Nick Treleaven wrote: Arrays evaluate to true in boolean conditions if their `.ptr` field is non-null. This is bug-prone and I hope we can remove this in the next edition. ... A string literal's `.ptr` field is always non-null, because it is

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-10 Thread Nick Treleaven via Digitalmars-d-learn
On Friday, 10 May 2024 at 15:23:39 UTC, Andy Valencia wrote: On Friday, 10 May 2024 at 03:07:43 UTC, Steven Schveighoffer wrote: Yes, we say that a type has "truthiness" if it can be used in a condition (`while`, `if`, `assert`, etc). So if I may ask for one more small clarification... WRT

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-10 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 10 May 2024 at 03:07:43 UTC, Steven Schveighoffer wrote: Yes, we say that a type has "truthiness" if it can be used in a condition (`while`, `if`, `assert`, etc). So if I may ask for one more small clarification... WRT "truthiness", I've observed that empty arrays are treated as

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 10 May 2024 at 01:00:09 UTC, Andy Valencia wrote: On Friday, 10 May 2024 at 00:40:01 UTC, Meta wrote: Yes. The reason for this is that it avoids having to essentially do the same check twice. If `in` returned a bool instead of a pointer, after checking for whether the element

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Andy Valencia via Digitalmars-d-learn
On Friday, 10 May 2024 at 00:40:01 UTC, Meta wrote: Yes. The reason for this is that it avoids having to essentially do the same check twice. If `in` returned a bool instead of a pointer, after checking for whether the element exists (which requires searching for the element

Re: "in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Meta via Digitalmars-d-learn
(123)); } Yes. The reason for this is that it avoids having to essentially do the same check twice. If `in` returned a bool instead of a pointer, after checking for whether the element exists (which requires searching for the element in the associative array), you'd then have to actually *get

"in" operator gives a pointer result from a test against an Associative Array?

2024-05-09 Thread Andy Valencia via Digitalmars-d-learn
tst7.d(6): Error: cannot implicitly convert expression `e in this.members` of type `bool*` to `bool` tst7.d(15): Error: template instance `tst7.Foo!uint` error instantiating I'm getting this for this bit of source (trimmed from the bigger code). I switched to this.members.get(e, false) and

Re: Accessing array elements with a pointer-to-array

2024-01-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 26 January 2024 at 11:38:39 UTC, Stephen Tashiro wrote: On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote: On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ];

Re: Accessing array elements with a pointer-to-array

2024-01-27 Thread Renato via Digitalmars-d-learn
On Friday, 26 January 2024 at 11:38:39 UTC, Stephen Tashiro wrote: On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote: On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ];

Re: Accessing array elements with a pointer-to-array

2024-01-26 Thread Sergey via Digitalmars-d-learn
On Friday, 26 January 2024 at 11:38:39 UTC, Stephen Tashiro wrote: On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote: On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ];

Re: Accessing array elements with a pointer-to-array

2024-01-26 Thread Stephen Tashiro via Digitalmars-d-learn
On Thursday, 25 January 2024 at 20:36:49 UTC, Kagamin wrote: On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ]; static_array[2][1] = 6; } The static array has length 2, so index 2 is out

Re: Accessing array elements with a pointer-to-array

2024-01-25 Thread Kagamin via Digitalmars-d-learn
On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: void main() { ulong [3][2] static_array = [ [0,1,2],[3,4,5] ]; static_array[2][1] = 6; } The static array has length 2, so index 2 is out of bounds, must be 0 or 1.

Re: Accessing array elements with a pointer-to-array

2024-01-25 Thread Sergey via Digitalmars-d-learn
On Thursday, 25 January 2024 at 20:11:05 UTC, Stephen Tashiro wrote: Can the elements of an array be accessed with a pointer using the usual indexing notation (e.g."[2][0]") for array elements? - or must we treat the elements associated with the pointer as 1-dimensional list and u

Accessing array elements with a pointer-to-array

2024-01-25 Thread Stephen Tashiro via Digitalmars-d-learn
Can the elements of an array be accessed with a pointer using the usual indexing notation (e.g."[2][0]") for array elements? - or must we treat the elements associated with the pointer as 1-dimensional list and use pointer arithmetic? A more elementary question is why array inde

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread Julian Fondren via Digitalmars-d-learn
On Thursday, 23 November 2023 at 20:13:59 UTC, BoQsc wrote: Nothing wrong. It would be just a more concise compact way to do the same. Also I mostly wanted to know if something like that is already possible in D language. It's not a huge loss if it is not possible. This is possible in Go:

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread BoQsc via Digitalmars-d-learn
On Thursday, 23 November 2023 at 20:00:31 UTC, H. S. Teoh wrote: On Thu, Nov 23, 2023 at 07:22:22PM +, BoQsc via Digitalmars-d-learn wrote: Is it possible to declare empty pointer variable inside function calls and pass its address to the function? These are sometimes required while using

Re: D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Nov 23, 2023 at 07:22:22PM +, BoQsc via Digitalmars-d-learn wrote: > Is it possible to declare empty pointer variable inside function calls > and pass its address to the function? > > These are sometimes required while using Win32 - Windows Operating > System API. >

D: Declaring empty pointer variables that return address inside function calls?

2023-11-23 Thread BoQsc via Digitalmars-d-learn
Is it possible to declare empty pointer variable inside function calls and pass its address to the function? These are sometimes required while using Win32 - Windows Operating System API. * Empty pointer variables are used by functions to return information after the function is done. My

Re: Associate information with a pointer address.

2023-10-01 Thread bachmeier via Digitalmars-d-learn
On Sunday, 1 October 2023 at 09:41:39 UTC, BoQsc wrote: The package dependency `emsi_containers` that can be found in https://code.dlang.org/packages/emsi_containers might be a viable way to resolve the problem. ``` /+dub.sdl: dependency "emsi_containers" version="~>0.7" +/ import std;

Re: Associate information with a pointer address.

2023-10-01 Thread BoQsc via Digitalmars-d-learn
The package dependency `emsi_containers` that can be found in https://code.dlang.org/packages/emsi_containers might be a viable way to resolve the problem. ``` /+dub.sdl: dependency "emsi_containers" version="~>0.7" +/ import std; void main(string[] args) @nogc { import containers;

Re: Associate information with a pointer address.

2023-09-29 Thread bachmeier via Digitalmars-d-learn
On Friday, 29 September 2023 at 14:31:54 UTC, BoQsc wrote: After being very happy about associative arrays of D Language, I encountered that they are not `@nogc`friendly. Unsure if I should wait for D language to support it, or do I need to rethink everything. You can work with AA's inside

Re: Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
After being very happy about associative arrays of D Language, I encountered that they are not `@nogc`friendly. Unsure if I should wait for D language to support it, or do I need to rethink everything. Error ``` onlineapp.d(20): Error: assigning an associative array element in `@nogc`

Re: Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
Out of scope access to a variable using stored pointer address, demonstration. ``` import std; void outofcontext() { writeln("Hello D ", associative); foreach (pointeraddress, information; associative) { writeln(*cast(string*)pointeraddress); } } static s

Re: Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
Bonus: Store hexadecimal literals in associative array of pointer addresses. ``` import std; void main() { string[void *] associative; // Store Hexadecimal as pointer address in associative array associative[cast(void *)0x7FFCD332CD60] = "someinformation";

Associate information with a pointer address.

2023-09-29 Thread BoQsc via Digitalmars-d-learn
For some reason I thought this was something I wanted to achieve and share. ``` import std; void main() { string variable; void * pointeraddress = string[void *] associative; associative[pointeraddress] = "someinformation"; writeln("Hello D ", pointeraddress);

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

2023-09-10 Thread ryuukk_ via Digitalmars-d-learn
On Friday, 8 September 2023 at 13:34:42 UTC, Richard (Rikki) Andrew Cattermole wrote: In case you didn't know, all you need to get unittests working in -betterC is: ```d foreach (module_; allModules) { foreach (unitTest;

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

2023-09-09 Thread rempas via Digitalmars-d-learn
On Saturday, 9 September 2023 at 10:54:34 UTC, bachmeier wrote: Hate to be that guy, but I posted a link to a stackoverflow question with the exact error message you were getting, and the solution. And I told you I had experienced the same error and that question fixed it. No reason to not

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

2023-09-09 Thread bachmeier via Digitalmars-d-learn
On Saturday, 9 September 2023 at 09:30:10 UTC, rempas wrote: Bingo! You and Brad found out! Hate to be that guy, but I posted a link to a stackoverflow question with the exact error message you were getting, and the solution. And I told you I had experienced the same error and that

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

2023-09-09 Thread rempas via Digitalmars-d-learn
On Saturday, 9 September 2023 at 09:56:59 UTC, H. S. Teoh wrote: libc doesn't know what you intended. All it knows is that you asked it for 20 bytes (even though you actually needed 40), then later on its internal structures are corrupted (because you thought you got 40 bytes; storing data

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

2023-09-09 Thread rempas via Digitalmars-d-learn
On Saturday, 9 September 2023 at 09:47:14 UTC, Steven Schveighoffer wrote: You are focusing on the wrong problem. You asked for size bytes, and malloc gave you size bytes. It doesn't "know" anything special. Then you proceeded at some point to write *past* the size bytes. What did you

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

2023-09-09 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, Sep 09, 2023 at 09:21:32AM +, rempas via Digitalmars-d-learn wrote: > On Saturday, 9 September 2023 at 08:54:14 UTC, Brad Roberts wrote: > > I'm pretty sure this is your problem. You're allocating size bytes > > which is only going to work where sizeof(T) == 1. Changing to > >

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

2023-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Saturday, 9 September 2023 at 09:21:32 UTC, rempas wrote: Now, if only one could expect how and why "libc" knows that and doesn't just care to give me the memory I asked it for? Or it could be than D does something additional without telling us? Which can explain when this memory is only

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

2023-09-09 Thread rempas via Digitalmars-d-learn
On Saturday, 9 September 2023 at 09:04:18 UTC, Steven Schveighoffer wrote: This is not ideal. Why? Because 99% of the time, a poster has come here with a problem they don't know how to solve, and have focused in on where they *think* the problem is. However, the problem isn't there. But us

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

2023-09-09 Thread rempas via Digitalmars-d-learn
On Saturday, 9 September 2023 at 08:54:14 UTC, Brad Roberts wrote: I'm pretty sure this is your problem. You're allocating size bytes which is only going to work where sizeof(T) == 1. Changing to malloc(size * sizeof(T)) is likely going to work better. Oh man That was it! I had forget

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

2023-09-09 Thread Steven Schveighoffer via Digitalmars-d-learn
On Friday, 8 September 2023 at 07:59:37 UTC, rempas wrote: I do have the following struct: ... That's some minimal code that I do have just to showcase it. This is not ideal. Why? Because 99% of the time, a poster has come here with a problem they don't know how to solve, and have focused

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

2023-09-09 Thread Brad Roberts via Digitalmars-d-learn
On 9/8/2023 12:59 AM, rempas via Digitalmars-d-learn wrote: u64 _cap = 0; // Total amount of elements (not bytes) we can this._ptr = cast(T*)malloc(size); I'm pretty sure this is your problem. You're allocating size bytes which is only going to work where sizeof(T) == 1. Changing to

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

2023-09-09 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 19:48:33 UTC, Basile B. wrote: My idea was that if you dont have defined a copy constructor and if an instance is assigned to another, then that other instance share the same pointer, which can cause memory errors. To eliminate that risk and to detect where

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

2023-09-09 Thread rempas via Digitalmars-d-learn
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. (Note that this may not immediately show up; free() could've assumed that everything was OK when it has in fact messed up its internal data structures

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

2023-09-09 Thread rempas 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. (Note that this may not immediately show up; free

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

2023-09-09 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 16:17:15 UTC, Richard (Rikki) Andrew Cattermole wrote: I would strongly suggest that you log all memory sizes that are allocated, and double check that you do free. Also turn on ASAN in ldc.

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

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

2023-09-08 Thread Basile B. via Digitalmars-d-learn
, then that other instance share the same pointer, which can cause memory errors. To eliminate that risk and to detect where default post-blitting may happen you can add ```d @disable this(this); ``` to the struct.

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

2023-09-08 Thread H. S. Teoh via Digitalmars-d-learn
nges slightly. 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. (Note that this may not immediately show up; free() could've assumed that everything was OK when it has in fact mes

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

2023-09-08 Thread rempas via Digitalmars-d-learn
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. The assertion seems to be violated when `malloc` is used. And when I assert the result in the `_ptr` field. Really weird...

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

2023-09-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 08/09/2023 7:59 PM, rempas wrote: |Fatal glibc error: malloc.c:2594 (sysmalloc): assertion failed: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)| I would strongly suggest

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: malloc error when trying to assign the returned pointer to a struct field

2023-09-08 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 07:59:37 UTC, rempas wrote: [I do have ... I do use ldc2 and `betterC`!] For anyone who is still following, first of all thanks! Second, I have bad news and good news! The bad news is that I tested in an Linux Mint system (mine is an Arch Linux) and the it

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

2023-09-08 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 14:40:13 UTC, Richard (Rikki) Andrew Cattermole wrote: No, for this you need ModuleInfo. The order is sequential on what it sees first. Personally I test using full D rather than -betterC. For dub: ```json "configurations": [ { "name":

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

2023-09-08 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 14:50:17 UTC, Kagamin wrote: Did you run this example program above? Does it crash? I didn't as I suppose that it would had no problems as it works for you. Either that, or it will be indeed a problem with my Glibc. I did run it now after your reply and it

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

2023-09-08 Thread Kagamin via Digitalmars-d-learn
On Friday, 8 September 2023 at 13:32:00 UTC, rempas wrote: On Friday, 8 September 2023 at 13:05:47 UTC, evilrat wrote: ```d import core.stdc.stdlib; import core.stdc.stdio; alias u64 = ulong; alias i64 = long; struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap

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

2023-09-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
On 09/09/2023 2:20 AM, rempas wrote: Do they have automatic symbol order resolution? Which is, testing symbols that other symbol depend on first? Or is it random? No, for this you need ModuleInfo. The order is sequential on what it sees first. Personally I test using full D rather than

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

2023-09-08 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 13:34:42 UTC, Richard (Rikki) Andrew Cattermole wrote: In case you didn't know, all you need to get unittests working in -betterC is: ```d foreach (module_; allModules) { foreach (unitTest;

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

2023-09-08 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
In case you didn't know, all you need to get unittests working in -betterC is: ```d foreach (module_; allModules) { foreach (unitTest; __traits(getUnitTests, module_)) { unitTest();

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

2023-09-08 Thread rempas via Digitalmars-d-learn
on your libc, tested this on ubuntu 23.04 with gcc12 install and ldc 1.32.2 ```d import core.stdc.stdlib; import core.stdc.stdio; alias u64 = ulong; alias i64 = long; struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap = 0; // Total amount of elements (not bytes

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

2023-09-08 Thread bachmeier via Digitalmars-d-learn
On Friday, 8 September 2023 at 07:59:37 UTC, rempas wrote: I do have the following struct: ```d struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap = 0; // Total amount of elements (not bytes) we can store public: /* Create a vector by just allocating memory

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

2023-09-08 Thread evilrat via Digitalmars-d-learn
this on ubuntu 23.04 with gcc12 install and ldc 1.32.2 ```d import core.stdc.stdlib; import core.stdc.stdio; alias u64 = ulong; alias i64 = long; struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap = 0; // Total amount of elements (not bytes) we can store u64 _len = 0

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

2023-09-08 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 09:25:59 UTC, Hipreme wrote: Hello, not completely unrelated to your problem, I have also done something like that, and when you're in D, don't use simply a pointer and length like that, use the `slice` operator. See references: https://tour.dlang.org/tour/en

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

2023-09-08 Thread rempas via Digitalmars-d-learn
On Friday, 8 September 2023 at 09:07:12 UTC, evilrat wrote: Hard to tell from that code but it is quite unlikely there is a compiler bug in such simple use case. I assume you already tried debugging your program, right? Yep! I have spent days and it's these kinds of bugs that burn me off

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

2023-09-08 Thread Hipreme via Digitalmars-d-learn
On Friday, 8 September 2023 at 07:59:37 UTC, rempas wrote: I do have the following struct: ```d struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap = 0; // Total amount of elements (not bytes) we can store public: /* Create a vector by just allocating memory

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

2023-09-08 Thread evilrat via Digitalmars-d-learn
On Friday, 8 September 2023 at 07:59:37 UTC, rempas wrote: I do have the following struct: ```d struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap = 0; // Total amount of elements (not bytes) we can store public: /* Create a vector by just allocating memory

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

2023-09-08 Thread rempas via Digitalmars-d-learn
I do have the following struct: ```d struct Vec(T) { private: T* _ptr = null; // The pointer to the data u64 _cap = 0; // Total amount of elements (not bytes) we can store public: /* Create a vector by just allocating memory for it. The null terminator is not set for strings

Re: Function Pointer

2023-08-31 Thread vino via Digitalmars-d-learn
On Wednesday, 30 August 2023 at 21:12:57 UTC, Paul Backus wrote: On Wednesday, 30 August 2023 at 17:48:19 UTC, Vino wrote: Hi All, Request your help on hot to create a pointer for a function whose function type is Result. ``` ReturnType!(typeof()).stringof; // Result From Vino

Re: pointer to std.algorithm.iteration : splitter

2023-08-31 Thread vino via Digitalmars-d-learn
On Thursday, 31 August 2023 at 10:46:53 UTC, Dukc wrote: On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote: [...] I'm assuming you want to instantiate `splitter` and take the address of the resulting function, so that `splitter_ptr` will be a function pointer or a delegate

Re: pointer to std.algorithm.iteration : splitter

2023-08-31 Thread Dukc via Digitalmars-d-learn
ntiate `splitter` and take the address of the resulting function, so that `splitter_ptr` will be a function pointer or a delegate. You are getting the compile time arguments to `splitter` utterly wrong. It should take: - A function that checks equality between an element

Re: pointer to std.algorithm.iteration : splitter

2023-08-31 Thread FeepingCreature via Digitalmars-d-learn
On Thursday, 31 August 2023 at 05:16:02 UTC, Vino wrote: Hi All, Request your help on the below error Program ``` void main() { import std.stdio:writeln; import std.algorithm.iteration : splitter; auto splitter_ptr = !((a, b) => a.splitter(b).array);

pointer to std.algorithm.iteration : splitter

2023-08-30 Thread Vino via Digitalmars-d-learn
Hi All, Request your help on the below error Program ``` void main() { import std.stdio:writeln; import std.algorithm.iteration : splitter; auto splitter_ptr = !((a, b) => a.splitter(b).array); string str = "TEST1;TEST2;TEST3"; auto words =

Re: Function Pointer

2023-08-30 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 30 August 2023 at 17:48:19 UTC, Vino wrote: Hi All, Request your help on hot to create a pointer for a function whose function type is Result. ``` ReturnType!(typeof()).stringof; // Result From Vino ``` To get a function pointer type from a function type, you can add

Re: Pointer to environment.get

2023-08-30 Thread Vino via Digitalmars-d-learn
Ext_PT = Ext_T*; // define a function **pointer** type Ext_PT ext = ``` But as you can see that does not allow to capture the argument. Also it only work as AliasDeclaration RHS. Thank you

Re: Pointer to environment.get

2023-08-28 Thread Basile B. via Digitalmars-d-learn
) = ("PATHEXT"); writeln(*ext); } ``` Problems is that "PATHEXT" is a runtime argument. If you really want to get a pointer to the function for that runtime argument you can use a lambda: ```d import std.stdio; import std.process: environment; void main () { a

Re: Pointer to environment.get

2023-08-28 Thread Basile B. via Digitalmars-d-learn
t "PATHEXT" is a runtime argument. If you really want to get a pointer to the function for that runtime argument you can use a lambda: ```d import std.stdio; import std.process: environment; void main () { alias atGet = {return environment.get("PATHEXT");}; // re

Pointer to environment.get

2023-08-28 Thread Vino via Digitalmars-d-learn
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); } ```

Re: Issue De-referencing a Pointer to a Struct in an Array

2023-07-14 Thread Steven Schveighoffer via Digitalmars-d-learn
On 7/14/23 1:23 PM, Pen Hall wrote: I think i figured out my issue... The issue was that 'board' is a pointer, and all of the ways I tried to de-reference it, failed. I just tried the form `(*board)[number][symbol][letter]` which worked to de-reference it. `&(*board)[number][symbol][le

Re: Issue De-referencing a Pointer to a Struct in an Array

2023-07-14 Thread Pen Hall via Digitalmars-d-learn
called `loopBoard()` that loops through certain parts of `board`. I then create a reference to the `Tile` struct at the current position of `board`. This all works until I try to de-reference that pointer. The result compiles, but I get the exit code `-1073741819` whenever I run it. Below

Re: Issue De-referencing a Pointer to a Struct in an Array

2023-07-14 Thread Pen Hall via Digitalmars-d-learn
of `board`. I then create a reference to the `Tile` struct at the current position of `board`. This all works until I try to de-reference that pointer. The result compiles, but I get the exit code `-1073741819` whenever I run it. Below is the function in question. Do any of you have literally any clue

Issue De-referencing a Pointer to a Struct in an Array

2023-07-14 Thread Pen Hall via Digitalmars-d-learn
at the current position of `board`. This all works until I try to de-reference that pointer. The result compiles, but I get the exit code `-1073741819` whenever I run it. Below is the function in question. Do any of you have literally any clue about where I'm screwing up? ```d void loopBoard(Tile

Re: compile-time detection of all pointer types in one test

2023-06-13 Thread DLearner via Digitalmars-d-learn
On Sunday, 11 June 2023 at 21:32:11 UTC, Andy wrote: [...] void main() { import std.stdio; struct foo {} foo* fooptr; static if (is(typeof(fooptr) == T*, T)) writeln("fooptr is a pointer to a ", T.stringof); else

Re: compile-time detection of all pointer types in one test

2023-06-12 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/11/23 5:25 PM, DLearner wrote: Is there any way of picking up, at compile-time, all pointer types in one test? What you want is `is(T : void *)` but probably to also catch all constancy flavors, `is(immutable(T) : immutable(void*))` When you use `==` in an `is` expression, it's

Re: compile-time detection of all pointer types in one test

2023-06-11 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
Just to be clear where the argument goes (from templates parameters ext.): ``is(InputType : T*, T)``

Re: compile-time detection of all pointer types in one test

2023-06-11 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
std.traits : isPointer or ``is(int* : T*, T)``

Re: compile-time detection of all pointer types in one test

2023-06-11 Thread Andy via Digitalmars-d-learn
iteln("genptr is void*"); else writeln("genptr is not void*"); } ``` which produces: ``` fooptr is not void* fooptr is foo* genptr is void* ``` Since `void*` variables accept _all_ pointer types, I expected to see `fooptr is void*`. Is there any way of

compile-time detection of all pointer types in one test

2023-06-11 Thread DLearner via Digitalmars-d-learn
writeln("genptr is not void*"); } ``` which produces: ``` fooptr is not void* fooptr is foo* genptr is void* ``` Since `void*` variables accept _all_ pointer types, I expected to see `fooptr is void*`. Is there any way of picking up, at compile-time, all pointer types in one test?

Re: How can a function pointer required to be extern(C)?

2023-04-13 Thread rempas via Digitalmars-d-learn
On Wednesday, 12 April 2023 at 21:00:04 UTC, John Chapman wrote: You can also express it like this: ```d extern(C) alias FuncPtr = void* function(void*); ``` Thank you! This is how I was planning to do anyway because other that the fact that I like the syntax of that a little bit more,

Re: How can a function pointer required to be extern(C)?

2023-04-13 Thread rempas via Digitalmars-d-learn
On Wednesday, 12 April 2023 at 20:36:59 UTC, H. S. Teoh wrote: IMO this is a bug either in D's syntax or in the parser. I'd file an enhancement request. In the meantime, you can use alias as a workaround: ---snip--- extern(C) void* abc(void*) {return null;} alias FuncPtr =

Re: How can a function pointer required to be extern(C)?

2023-04-12 Thread John Chapman via Digitalmars-d-learn
On Wednesday, 12 April 2023 at 20:36:59 UTC, H. S. Teoh wrote: ---snip--- extern(C) void* abc(void*) {return null;} alias FuncPtr = typeof(); You can also express it like this: ```d extern(C) alias FuncPtr = void* function(void*); ```

Re: How can a function pointer required to be extern(C)?

2023-04-12 Thread H. S. Teoh via Digitalmars-d-learn
d; } > } > > ``` > > Yes, I'm trying to "encapsulate" the Pthread (POSIX threads) API. > Normally, the function pointer that is passed to "pthread_create" must > be "extern(C)" and this is the complaining that the compile does. So, > I'm thinking

How can a function pointer required to be extern(C)?

2023-04-12 Thread rempas via Digitalmars-d-learn
(pthread_attr_t*) attr = null) { pthread_create(_id, attr, func, arg); } @property: pthread_t id() { return this.thread_id; } } ``` Yes, I'm trying to "encapsulate" the Pthread (POSIX threads) API. Normally, the function pointer that is passed to "pthread_create"

Re: constant pointer failing to compile

2023-04-06 Thread Jacob Shtokolov via Digitalmars-d-learn
pointer will also work in D's version, although it's probably a bit uglier.

Re: constant pointer failing to compile

2023-04-06 Thread Jacob Shtokolov via Digitalmars-d-learn
On Thursday, 6 April 2023 at 00:46:26 UTC, Josh Holtrop wrote: I am trying to port a small C project to D and am getting a compilation error I don't understand. It seems like the compiler is just missing some type hints. Try this: ```d import std.stdio; __gshared immutable ubyte[4] data =

Re: constant pointer failing to compile

2023-04-06 Thread Salih Dincer via Digitalmars-d-learn
On Thursday, 6 April 2023 at 00:46:26 UTC, Josh Holtrop wrote: ``` constarrptr.d(5): Error: cannot use non-constant CTFE pointer in an initializer `cast(immutable(ubyte)*)data` ``` Why? And how can I do the equivalent to what I have been doing in C? I want these pointers to be generated

Re: constant pointer failing to compile

2023-04-06 Thread Josh Holtrop via Digitalmars-d-learn
On Thursday, 6 April 2023 at 00:59:12 UTC, Mathias LANG wrote: immutable ubyte[4] data = [1, 2, 3, 4]; Using a static array instead of a slice will do the trick. You can leave the `__gshared` if you want, but it is redundant on a global, initialized `immutable` variable. Yes, thank you,

Re: constant pointer failing to compile

2023-04-05 Thread Steven Schveighoffer via Digitalmars-d-learn
really understand why. the error message gives a slight clue: ``` cannot use non-constant CTFE pointer in an initializer ‘&[cast(ubyte)1u, cast(ubyte)2u, cast(ubyte)3u, cast(ubyte)4u][0]’ ``` That *isn't* a CTFE pointer, it's a pointer to a static immutable. Yes, the initialization v

Re: constant pointer failing to compile

2023-04-05 Thread Mathias LANG via Digitalmars-d-learn
immutable ubyte[4] data = [1, 2, 3, 4]; Using a static array instead of a slice will do the trick. You can leave the `__gshared` if you want, but it is redundant on a global, initialized `immutable` variable.

constant pointer failing to compile

2023-04-05 Thread Josh Holtrop via Digitalmars-d-learn
;, *p); return 0; } ``` This fails to compile with gdc: ``` constarrptr.d:5:45: error: cannot use non-constant CTFE pointer in an initializer ‘&[cast(ubyte)1u, cast(ubyte)2u, cast(ubyte)3u, cast(ubyte)4u][0]’ 5 | __gshared immutable(immutabl

Re: How can I get the scalar type of a pointer to pointer (and in even deeper levels)

2023-03-11 Thread rempas via Digitalmars-d-learn
On Saturday, 11 March 2023 at 13:37:26 UTC, ag0aep6g wrote: On 11.03.23 14:22, rempas wrote: On Saturday, 11 March 2023 at 12:59:59 UTC, ag0aep6g wrote: alias Foo(T : U*, U) = Foo!U; alias Foo(T) = T; static assert(is(Foo!(int*) == int)); static assert(is(Foo!(int**) == int)); static

Re: How can I get the scalar type of a pointer to pointer (and in even deeper levels)

2023-03-11 Thread ag0aep6g via Digitalmars-d-learn
On 11.03.23 14:22, rempas wrote: On Saturday, 11 March 2023 at 12:59:59 UTC, ag0aep6g wrote: alias Foo(T : U*, U) = Foo!U; alias Foo(T) = T; static assert(is(Foo!(int*) == int)); static assert(is(Foo!(int**) == int)); static assert(is(Foo!(int***) == int)); static assert(is(Foo!(int) ==

Re: How can I get the scalar type of a pointer to pointer (and in even deeper levels)

2023-03-11 Thread rempas via Digitalmars-d-learn
On Saturday, 11 March 2023 at 12:59:59 UTC, ag0aep6g wrote: alias Foo(T : U*, U) = Foo!U; alias Foo(T) = T; static assert(is(Foo!(int*) == int)); static assert(is(Foo!(int**) == int)); static assert(is(Foo!(int***) == int)); static assert(is(Foo!(int) == int)); Wait, but "Foo" is defined

  1   2   3   4   5   6   7   8   9   10   >