1

I have to define high level definition of objects such as :

obj1 => [
    name => "object1",
    type => "uint64",
    dependents => [
         {type  => "unit32", name => "dep1"},
         {type  => "uint32", name => "dep2"}
    ],
    default_value = "100"
]

From this I want to generate the C structures and some helper routines such as:

struct_dependents {
    int type;
    char name[MAX];
}

struct struct_obj1 {
     char name[MAX];
     int  type;
     struct dependents deps[MAX_DEP];
     unit64 default_value;
}

// Some initializations..

Earlier I thought I could define the high level objects in .pm (perl module) files and then use perl to generate C code, but writing code to generate C code this way might be error prone and tough to maintain if object definitions change in future.

What I want to know is that - are there any such ready made tools which allow us to write high level object definition and auto generate their C structures?

2
  • Why would it be error prone? Why do you need to define C structures in something other than C? Why would there be tools that understand your definition language, or what are you looking in a definition language?
    – ikegami
    Commented Oct 13, 2014 at 3:51
  • the idea is to expose the high level object definition to wider audience (even customers) for their quick understanding, for this we don't want to expose C code.
    – pankaj
    Commented Oct 13, 2014 at 5:03

1 Answer 1

1

There are plenty of code generators for C - you're more likely to find something that uses an intermediary syntax such as xml; A quick google turned up xml2c. You can use XML::Simple for saving your hashes to xml.

More examples can be found on google.

If you wish to roll out your own, code generation using template toolkit provides a flexible approach.

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.