I have C source code that is generalized either by preprocessing directives or compile-time optimizations, for example the ones shown below. Is there any command-line tool that can help to take code like this:
int16_t foo(FOO_STATE* fooState) {
#if SUPPORTS_WOMBAT_OPTION
int16_t bar = get_bar_from(fooState);
return bar + 1;
#else
int16_t baz = get_baz_from(fooState);
return baz - 1;
#endif
}
or this:
bool supportsWombat(void) {
#if SUPPORTS_WOMBAT_OPTION
return true;
#else
return false;
#endif
}
int16_t foo(FOO_STATE* fooState) {
if (supportsWombat()) {
int16_t bar = get_bar_from(fooState);
return bar + 1;
} else {
int16_t baz = get_baz_from(fooState);
return baz - 1;
}
}
and transform to the appropriate one of the following, if I know I am working with a system where the value of SUPPORTS_WOMBAT_OPTION
is always known?
for SUPPORTS_WOMBAT_OPTION = 1
:
int16_t foo(FOO_STATE* fooState) {
int16_t bar = get_bar_from(fooState);
return bar + 1;
}
for SUPPORTS_WOMBAT_OPTION = 0
:
int16_t foo(FOO_STATE* fooState) {
int16_t baz = get_baz_from(fooState);
return baz - 1;
}