macros for bool's sake

Found some very interesting things that can be done with variable macro arguments. If everything goes right, I can do some limited, through compile-intensive template macros for generating C functions. Disadvantage: you can't debug it properly as macro evaluations always count as one line. But well, it's proof of concept after all. I'm working quite a lot with much needed clever macro contructs that utilize anonymouse temporary variables inside expressions, processing argument lists and so on. Quite a bunch of good things came out so far. May be even better to summarize this and do a complete post of good practice I've found so far. Yep, this way they may be people out there finding my blog somehow and improve their thinkage around macros. After all, macros are the only way to really add something to C. Pure C code on it's own without the preprocessor is hard to upgrade in any way. All stuff will still be direct code and any clever construct can't be reused except using functions, though this will make inlining more important than happening in C compilers. Sooo, macros are crucial to syntactical improvement of C code without writing a new language.

However, did I yet told you about WHAT I archieved so far aside from totally generic gibberish about how great this and that is? Templates in C! Yep, though a bit limited. Templates in C can be very easy to make by defining macros, but you'll have to put the whole code into one macro, waste the proprocessor space with more symbols while obfuscating the code itself with a lot of \'s and whatever else. It's also not visible to the user and you'll have to instantiate the functions before using them (really stupid if you intend to create a library with all sorts of premade functions but only provide the macros!) and can't just put them into one place and say that only these functions with these types are possible. All in all it may be of use to those wanting to provide a way for really EVERY type out there, but the more library-bound type of template instanciation was more important to me. They are rather simple to use, though a bit complicated compared to templates from macros but provide extra options for symbol generation and so on. It also requires a lot of preprocessing - maybe not optimal for a whole lot of instances. I'll freeze my work on IGE for a moment and try putting all this macro stuff into ITK, fix some bugs in ITK and it's thread syste and release a new version of it. Part of this will be my OOP system on a macro for which I can utilize my new macro sets, too - they'll definitely profit what it's capable of. Handling argument lists using __VA_ARGS__ really is the best base for truly amazing stuff; I'll do write-up of it as soon as I get the time for it. Too bad that I'll have to attend a ridiculous "meat feast" during which I'll probably starve from not beeing able eat anything due to some stupid relatives not knowing how to cope with people different from their own nut-sized brains.

No comments: