0

I'm working on a project for an embedded processor where I have some data which is created at runtime, and pointers to this data need to be arranged into several binary tree-like data structures for use by the program.

These structures will be fixed for the duration of the program, however, I would like the option at compile time to be able to quickly change how the trees used are structured. Something hopefully more elegant and easily re configurable than say, a function or macro for every tree involved that repeatedly calls the "AddNode" function in the proper order for each underlying data element and node of the tree. Thanks for any suggestions!

3
  • 1
    How about creating a textual representation of the tree and keeping it in a string, and then parsing it to build the tree? You can then switch which string is being used at compile time. Commented Oct 14, 2012 at 13:48
  • 1
    I generally used utilities that created a memory image of the structure, either directly as binary, or symbolically, with fixups done either by the linker, or by the utility. Commented Oct 14, 2012 at 13:49
  • Thanks - both of these are appealing suggestions. Commented Oct 14, 2012 at 15:04

1 Answer 1

1

How about using the M4 preprocessor to implement a high-level pseudo-language to generate the C code required to build trees? Your code may have a function called, for instance, initTrees() whose body would be autogenerated by M4 from a file whose content would be a description of the desired tree structure. The overall process would be as follows:

sample.c.m4 ---> [M4] ---> sample.c ---> [C compiler] ---> Binary file

http://www.gnu.org/software/m4/

http://en.wikipedia.org/wiki/M4_(computer_language)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this is certainly worth considering!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.