News for hackers. Stuff that matters.
Re:Struct Iteration Through Abuse of the C Preprocessor by ncraun on Tuesday October 13, 2015 @11:57AM (#10381289)
In actual production use, I think it could be better to write a separate program that will generate the code for you instead of using the C preprocessor (or use a language with this kind of introspection built in). However, using this hack lets you depend only on the facilities of the language, and that can be useful in simplifying the build process. Plus it was fun to create, too!
Re:Struct Iteration Through Abuse of the C Preprocessor by uxcn on Tuesday October 13, 2015 @12:20PM (#10381479)
It can be a bit tricky if it isn't integrated with the build process.
Re:Struct Iteration Through Abuse of the C Preprocessor by Kristine1975 on Tuesday October 13, 2015 @01:40PM (#10382066)
You can use e.g. cog which puts the generated code into the file itself: http://nedbatchelder.com/code/cog/ Then all you need to do is to remember to run the preprocessor after you've made a change to the generator code.
Re:Struct Iteration Through Abuse of the C Preprocessor by uxcn on Tuesday October 13, 2015 @03:01PM (#10382677)
Python is definitely a better syntax to write meta-programs than the pre-processor, but you still have the issue of the additional step/tool. Anything that depends on the generated code depends on the step which, if it's missed, can lead to non-good things.
Re:Struct Iteration Through Abuse of the C Preprocessor by Kristine1975 on Wednesday October 14, 2015 @02:50AM (#10385326)
Sure. But you do test your changes, don't you? ;-) So if you forget to run cog after making a change to the meta-program, you should notice right away.

But it still is a cludge. It would be better if C/C++ had a better preprocessor.

Re:Struct Iteration Through Abuse of the C Preprocessor by uxcn on Wednesday October 14, 2015 @11:22AM (#10387110)
It isn't a question of testing changes. The more people working on the codebase, the more people it impacts. Adding manual steps is tempting the fates.