SO, i had to create "Expand" and "Extract" functions to convert between
No, the generic programming capabilities of C are very limited.
But you have some options. Follow your idea with the #include
"function.c ",
but if you do not want to include a file twice, copy in with an other
name,
this fits well in a Makefile.
<off>
If you accept a program with several object files, why don't you
create
a source file with this expand function, where the type name is a
macro.
Then in the makefile you compile this expand.c as
expand1.o: expand.c type1.h expand.h
cc -E -Dtype=type1 -c expand.c
expand2.o: expand.c type.h expand.h
cc -E -Dtype=type2 -c expand.c
</off>
Your source generator can be the combination of the preprocessor and
make.
Szabolcs
the two versions of the "setup_t" structure, like so:
>
int ExpandSetupFrom 1400 (setup1400_t const *in, setup_t *out)
{
if (!in || !out) return 666;
memset(out, 0, sizeof(*out));
out->CoolStages = in->CoolStages;
out->HeatStages = in->HeatStages;
(several hundred more lines of "out->foo = in->foo;")
return 42;
} // end ExpandSetupFrom 1400()
>
int ExpandSetupFrom 1400 (setup1400_t const *in, setup_t *out)
{
if (!in || !out) return 666;
memset(out, 0, sizeof(*out));
out->CoolStages = in->CoolStages;
out->HeatStages = in->HeatStages;
(several hundred more lines of "out->foo = in->foo;")
return 42;
} // end ExpandSetupFrom 1400()
But you have some options. Follow your idea with the #include
"function.c ",
but if you do not want to include a file twice, copy in with an other
name,
this fits well in a Makefile.
<off>
If you accept a program with several object files, why don't you
create
a source file with this expand function, where the type name is a
macro.
Then in the makefile you compile this expand.c as
expand1.o: expand.c type1.h expand.h
cc -E -Dtype=type1 -c expand.c
expand2.o: expand.c type.h expand.h
cc -E -Dtype=type2 -c expand.c
</off>
Your source generator can be the combination of the preprocessor and
make.
Szabolcs