#sparse array of optionals

1 messages · Page 1 of 1 (latest)

ruby burrow
#

in C i could do something like this:

void *vectors[] = {
  [29] = some_handler
};

is there an alternative to that in zig? i don't care what values will be on unspecified places but null would be nicer

shrewd agate
#
const vectors = blk: {
  var array = std.mem.zeroes([N]?*const fn () void);
  array[29] = some_handler;
  break :blk array;
};

although this seems like an XY problem

ruby burrow
#

sorry, what's that?

shrewd agate
#

an XY problem is asking about your attempted solution rather than potentially the real problem. For a crude example: "how do I implement a garbage collector" when you really only need defer free() in one instance.

ruby burrow
#

well, i don't see other solutions because it's a hardware thing

shrewd agate
#

is it a case of memory mapped IO, IDT, or like JIT?

ruby burrow
#

IDT ig, not 100% sure, it's for interrupt vector

shrewd agate
#

makes sense, something like the comptime array may work then. Although it could also be initialized at runtime

ruby burrow
#

it'd be rather complicated

#

because by default there's a flash memory mapped onto the area with the vectors