Issue De-referencing a Pointer to a Struct in an Array
Pen Hall
aidencbernstein at gmail.com
Fri Jul 14 17:23:37 UTC 2023
On Friday, 14 July 2023 at 17:14:01 UTC, Pen Hall wrote:
> On Friday, 14 July 2023 at 16:57:33 UTC, Pen Hall wrote:
>> Hello!
>> In my program, I have defined a struct called `Tile` in the
>> global scope. In my `main()` function I create a 3d array of
>> `Tile`s called `board`. I then have a function 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 is the
>> function in question. Do any of you have literally any clue
>> about where I'm screwing up?
>>
>> [...]
>
> I realized a slight issue with this code is that
> `board[number][symbol][i]` refers to an array... somehow. I
> genuinely have no idea as to why this is.
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][letter]`, of course, works to get
a pointer to that spot in memory.
More information about the Digitalmars-d-learn
mailing list