Can I coerce C++ construction of objects to happen at compile time, even for relatively complex objects?
In particular, suppose I want to build a linked list of keywords:keyword *listhead = NULL;
keyword _if(listhead, "if", process_if);keyword _else(listhead, "else", process_else);keyword _while(listhead, "while", process_while);And I have constructor/object code that looks somewhat like:class keyword {
public:
const char *text;
void (*func)(char *);
keyword *next;
keyword(keyword *&head, const char *t, void(*f)(char *)) {
text = t;
func = f;
next = head;
head = this; // add to beginning of linked list
}
};
In theory, that could all happen at compile time, leaving me with a linked list that could theoretically be "const" and stuck in ROM instead of precious RAM.
Is there a way to make this happen?