Re: Pointer vs Ref

2025-07-04 Thread confuzzled via Digitalmars-d-learn
On 6/15/25 9:06 AM, Steven Schveighoffer wrote: On Monday, 9 June 2025 at 07:24:41 UTC, confuzzled wrote: Hello community, Is it possible to accomplish the following using ref instead of pointers? If so, please share an example. A ref cannot be a member of a type. But ref can be returned by

Interact with local variables in asm block

2025-07-04 Thread confuzzled via Digitalmars-d-learn
Good day all, What is the proper way to assign to accomplish this? ulong rdtsc() { ulong result; uint* res = cast(uint*) &result; asm { rdtsc; // Puts result in edx:eax // Cast our ulong's address to a 32-bit integer pointer // and move the register values i

Re: Looking for a simple GUI library that works with Vulkan on SDL2

2025-07-04 Thread IchorDev via Digitalmars-d-learn
On Thursday, 20 February 2025 at 10:05:13 UTC, Danny Arends wrote: Running into some weird linker issues within bindbc.common.codegen: ``` /usr/bin/ld: /home/danny/.dub/cache/betterct/~master/build/betterC-debug-gZx8lRyN8EaQ6hq_UuhHCw/betterct.o:(.data._D39TypeInfo_S6bindbc6common7codegen6FnBi

why is the behavior of pointers to 0 width doing this?

2025-07-04 Thread monkyyy via Digitalmars-d-learn
```d import std; unittest{ int[0] callstack; (&callstack).writeln; (&callstack+1000).writeln; } ``` this prints the same value twice, I assume its some kind of void replacement, then an optimizer, then related to whatever os memory magic does some math.

Re: why is the behavior of pointers to 0 width doing this?

2025-07-04 Thread Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
```d import std.stdio; __gshared int literal; void main() { int[0] callstack; (&callstack+literal).writeln; } ``` ```asm _Dmain: .Lfunc_begin0: .file 1 "/" "app/example.d" .loc1 5 0 .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16

Re: How can I signal a master object that a resource handle is no longer used, from within the resource class's destructor?

2025-07-04 Thread realhet via Digitalmars-d-learn
On Saturday, 28 June 2025 at 08:11:53 UTC, realhet wrote: On Thursday, 26 June 2025 at 16:40:10 UTC, Steven Schveighoffer wrote: On Tuesday, 24 June 2025 at 08:48:16 UTC, realhet wrote: For those who run into this problem: These are really illegal things in the destructors: - GC allocation.

Re: why is the behavior of pointers to 0 width doing this?

2025-07-04 Thread monkyyy via Digitalmars-d-learn
On Friday, 4 July 2025 at 08:17:34 UTC, Richard (Rikki) Andrew Cattermole wrote: ```d import std.stdio; __gshared int literal; void main() { int[0] callstack; (&callstack+literal).writeln; } ``` ```asm _Dmain: .Lfunc_begin0: .file 1 "/" "app/example.d" .loc1 5 0

Why this doesn't produce an error or works as expected?

2025-07-04 Thread partypooper via Digitalmars-d-learn
```d struct Vector { float x, y; Vector opBinary(string op)(inout Vector rhs) const if (op == "+") { return Vector(mixin("x", op, "rhs.x"), mixin("y", op, "rhs.y"),); } ref Vector opOpAssign(string op)(inout Vector rhs) if (op == "+" || op == "-") {

Re: Why this doesn't produce an error or works as expected?

2025-07-04 Thread monkyyy via Digitalmars-d-learn
On Friday, 4 July 2025 at 17:15:48 UTC, partypooper wrote: ```d struct Vector { float x, y; Vector opBinary(string op)(inout Vector rhs) const if (op == "+") { return Vector(mixin("x", op, "rhs.x"), mixin("y", op, "rhs.y"),); } ref Vector opOpAssign(string op)(in

Re: Why this doesn't produce an error or works as expected?

2025-07-04 Thread partypooper via Digitalmars-d-learn
On Friday, 4 July 2025 at 17:34:59 UTC, monkyyy wrote: On Friday, 4 July 2025 at 17:15:48 UTC, partypooper wrote: if you add ref to line 28 it works; there wont be a reasonable way to make an error happen, you just have to know when to do refness It doesn't work. Or it works even worse: chang

Accessing the parents arguments from a child function call

2025-07-04 Thread monkyyy via Digitalmars-d-learn
```d auto bar(int i){ foo() } unittest{ bar(3); } ``` Given any definition of foo, any compiler bugs, how would you detect the `3` from `foo`? ___ My attempts at scanning the call stack didn't work but for anyone attempting it, I believe this breakdown of control flow may be part of the

Re: Why this doesn't produce an error or works as expected?

2025-07-04 Thread partypooper via Digitalmars-d-learn
On Friday, 4 July 2025 at 18:04:55 UTC, partypooper wrote: It doesn't work. Or it works even worse: changing _pos, but not _dest. What is going on is that on `+=` it for some reason invokes "getter", not "setter". I specifically omitted "ref", because I already have known of that behavior. In

Re: Interact with local variables in asm block

2025-07-04 Thread confuzzled via Digitalmars-d-learn
On 7/5/25 1:06 AM, confuzzled wrote: ulong rdtsc() {     ulong result;     uint* res = cast(uint*) &result;     asm {     rdtsc;  // Puts result in edx:eax     // Cast our ulong's address to a 32-bit integer pointer     // and move the register values into the correct memory lo