Creating a compile-time array for ANSI-C?

The previous programmer preferred to generate large lookup tables (arrays of constants) to save processor cycle time rather than calculating values ​​on the fly. He did this by creating custom Visual C ++ projects that were unique to each individual lookup table ... that generate array files that are then included in a completely separate ANSI-C microcontroller project (Renesas).

This approach is good for its initial calculation assumptions, but it became tedious when the input parameters needed to be changed, requiring me to recompile all Visual C ++ projects and re-import these files into the ANSI-C project. What I would like to do is pass the Visual C ++ source code directly to the ANSI-C microcontroller project and let the compiler create the array tables.

So my question is: can ANSI-C compilers compute and generate search arrays at compile time? And if so, how do I do this?

Thanks in advance for your help!

+3
source share
3 answers

, ?

, make - :

TABLES:=$(wildcard table_*)
TABLE_INCS:=$(foreach dir,$TABLES,$dir/$dir.h)
include $(foreach dir,$TABLES,dir/makefile.inc)

$MAIN: $(SRS) $(TABLE_INCS)

table_* , table_n/table_n.h. makefile makefile.inc, include, .

( , , , , ), table_3/table_3.input, make table_3/table_3.h .

+4

, , . , , , , .

+1

Check out the Boost preprocessor library. This is written for C ++, but as far as I know, both preprocessors are pretty much identical, and it can do such things.

0
source

Source: https://habr.com/ru/post/1737561/


All Articles