#@fieldParentPtr with pointer to element in fixed array

1 messages · Page 1 of 1 (latest)

rain stream
#

I'm converting some old code to the new linked list API.

const EntityData = struct {
    tile_nodes: [num_nodes_per_entity]std.SinglyLinkedList.Node,
};

Given a *std.SinglyLinkedList.Node, how can I get to the parent *EntityData?

I tried just @fieldParentPtr("tile_nodes", node), but got expected type '*[16]SinglyLinkedList.Node', found '*SinglyLinkedList.Node'

vague harness
#

@fieldParentPtr is about going from &something.field to &something.

#

It does that by knowing the offset between the two and being told which field you're pointing at.

#

That offset is part of the type definition.

rain stream
#

Hmm. I guess I will have to completely rework it 🤔

vague harness
#

You'd need to have a way to figure out, or know, which Node you're pointing at.

#

If it even is one of those 16.

#

You could consider doing pointer arithmetic.

#

You'd need to already know &something.tile_nodes[0] for that however

rain stream
#

Thanks for the pointers (ha). I will have to think about this some more.

vague harness
#

Ha

#

Welcome