C Preprocessor Hell
jacquesmattheij.com
jacquesmattheij.com
You aren't required to only use the C source code transformation tools that a default install of GCC provides.
If you're about to reply it's a risk you'd take... me too, in general. CPP sucks. But not wanting to introduce that risk is a valid choice in many cases.
Doing weird things to a C file (while occasionally useful) is just increasing the technical debt of your teammates later.
(though, we do have a closure-ish macro in our codebase that's pretty nifty, so do as I say not as I do etc.)
>> If you really want to do complicated lisp-style meta-programming stuff
> Increases technical debt
Yep. The sane solution is to just not do stuff like this at all. In rare
situations it ends up being worth it.No it doesn't. It only requires a single rule in your Makefile. Something like:
%.c: %.cpre preprocess.pl; ./preprocess.pl <$^ >$@The usual workaround for such situations is to add the preprocessed files into source control as well, so they are available when a user is building the code. However, this ends up even more ugly.
But sure, if that's not one of the limitations you're working under then code generation through another language is definitely a possibility.
If you're using VS, you're going to want to use the included pre-build steps in the vcproj to generate the source. Unfortunately, you can't just edit the source in place, unless your team is absolutely in love with your SCS' rollback capability. So that means that in order to edit the code, you need to open it up in either another project, or open it outside the IDE's solution environment.
It also removes the ability to do partial rebuilds, since every file will be necessarily touched by the preprocessing script before compiling, so it's a "new" file as far as the IDE is concerned.
Debugging becomes a chore, because the code in source control is not the code that was compiled, breaking line counts and breakpoints.
Finally, it's a deployment nightmare for your build staff, since they need to make sure that everyone is standardized on the same perl version, maintain the scripts in addition to the makefiles, and make sure that everyone's dev environment works with it.
X-Macros: you have a header file consisting of lines in the form of "FOO(name, type, defvalue);" and include it several times with different definitions for FOO.
Thanks for the tip, I'll have a look at them to see if there is a way around that so that it would work from a 'top' included file as well.
The project I'm working on has a single 'master include' file and I'd hate to break that convention.
In this specific case, it might make more sense to have the programmer tell you how many arguments to expect and work with it that way, rather than going through this chain of macros. C doesn't allow function arguments to change dynamically, so that might be a slightly better approach. It would be easier to understand, but a bit harder to maintain code that uses it.
Naive question: in Lisp, how would you set the byte at address 0xDEADBEEF to 0x42?
(overlay 'light #on)
overlay being a macro to access a predefined ffi setup.</dream>
Also, in response to your first point: http://en.wikipedia.org/wiki/Lisp_machine
Quite easy.
(setf (cffi:mem-ref (cffi:make-pointer #xDEADBEEF) :int) #x42)