6 ms·
Meh, there is already an idiom for that. It's #include "data.h" Where data.h has "extern double array[SIZE][SIZE];" and data.c has the data. I don't see wha
by chubot 13y ago
Meh, there is already an idiom for that. It's
#include "data.h"
Where data.h has "extern double array[SIZE][SIZE];" and data.c has the data. I don't see what's clever or useful about this.
- angersock 13y agoHere, "float_values.txt" could just be a pile of comma-separated numbers, suitable for editing by non-programmers. It's a cute hack.
- chubot 13y agoI've worked in a lot of situations with C/C++ code and non-programmers, and that simply wouldn't work. Non-programmers will break your build with such a mechanism. If they are capable of editing comma-separated lists of numbers in a text editor without breaking it, they are capable of editing a C file with a float[][] declaration at the top. It would cause a problem after about 2 days, and then you would end up replacing this in 5 minutes with a 5 line Python script that does a minimal amount of error checking (or a higher level tool to generate the data, e.g. a game logic editor). EDIT: A cute hack is one that lets you take a shortcut and saves you time. This is one that saves a tiny amount of typing (or writing 5 lines of Python), in exchange for wasting time with broken builds.
- apaprocki 13y agoTaking that pattern to the next level is Mozilla Spidermonkey, which defines a macro and then includes a static data file which calls the macro with its data contents. The same table is included multiple times with different macro definitions to output different code. Pre-processor code generation :) Example: http://hg.mozilla.org/mozilla-central/file/48dbd532a004/js/src/jsopcode.cpp#l60 http://hg.mozilla.org/mozilla-central/file/48dbd532a004/js/s...
- Someone 13y agoThat's pretty normal, if used in moderation. For example, it is a way to define overloads on functions on vectors with floats and double coordinates without having to copy-paste thousands of lines (using sed and make is another) http://www.drdobbs.com/the-new-c-x-macros/184401387 http://www.drdobbs.com/the-new-c-x-macros/184401387 gives nice examples.