Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternatives/Tools for #define hell C/C++

In our C/C++ Project we use a configuration header (~1000 lines) that is full of #ifdef's and #defines

#if (defined(HW_1) || defined(SOME_TECHNOLOGY_SUPPORTED)) && defined(OTHER_TECHNOLOGY_SUPPORTED)
 #define SOME_FEATURE_AVAILABLE
#endif

In our build configuration we predefine some defines that are passed to the compiler. This results in different defines (like SOME_FEATURE_AVEILABLE) in our configuration header.

Since our configuration header is quite big, there is also a bit of a mess.

Are there any alternatives for this #define hell?

Or are there any tools that help to see in what case which defines are set.

We are developing embedded firmware so we can't replace conditional compiling by runtime if's.

like image 225
woodtluk Avatar asked Aug 08 '13 10:08

woodtluk


People also ask

How do I find alternatives to apps?

Use the Play Store: The most basic way is to use the Google Play Store to find alternatives. Simply go to the tab of the application you want and look in the lower area.


1 Answers

In case all your #define's are in a single configuration file, you can try doing a preprocessor-only compilation and then finding all defined macros. E.g.,

$ gcc -DFEATURE1 -DFEATURE2 -E configuration.h | grep '#define'
like image 178
Subhasis Das Avatar answered Sep 17 '22 19:09

Subhasis Das