C++ question:

void (*sFuncs)(void)[] = { funcA, funcB };
enum {

Is there a simple C++ way without X-macros to build the enum (or some other symbolic name for the function indexes in the array?) from the function list?

@uliwitness Uli, I can’t work out the syntax without jumping on my computer, but I don’t know how to do what you’re attempting.

I’m sure you’ve boiled this down to a very simple example and really want that enum, but if you eliminate it and just jam the function names into the array that’s easily doable.

I’m sorry that doesn’t answer the question.

@fahrni Basically, I'm generating bytecode for a virtual CPU, so I need the numbers from the enums to persist them to disk (can't persist a function address). But yeah, conceptually it's all just the function pointers.

But since this is for a tutorial, I did arrive at the conclusion too that I might just stick the function pointer in there and postpone discussion of saving to later.

@uliwitness 👍🏼

You could persist the function names. 🤔

@uliwitness I suppose you could also persist the enum value and map that to the index of the function pointer in the array?

@fahrni That's what I'm doing when I have the enum. But that means I need to keep the array and the enum indexes in sync, which is info the C compiler could just derive.

Sign in to participate in the conversation
Mastodon for Tech Folks

mastodon.technology is shutting down by the end of 2022. Please migrate your data immediately. This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!