☰
Current Page
Main Menu
Home
Home
Editing ConfigDefines
Edit
Preview
H1
H2
H3
default
Set your preferred keybinding
default
vim
emacs
markdown
Set this page's format to
Markdown
Plain Text
Pod
RDoc
reStructuredText
Rendering unavailable for
AsciiDoc
BibTeX
Creole
MediaWiki
Org-mode
Textile
Help 1
Help 1
Help 1
Help 2
Help 3
Help 4
Help 5
Help 6
Help 7
Help 8
Autosaved text is available. Click the button to restore it.
Restore Text
--- title: ConfigDefines --- Quick, tidy, feature #defines. * Centralizes build-time configuration. * Imports a list of #defines from Config.inc and applies a set of rules defining dependent features. Convenience macros are provided in order to free code from #ifdef clutter, allowing one to write if (have(SOME_FEATURE)) use_some_feature(); instead of #if defined SOME_FEATURE use_some_feature(); #endif Also allows configuration tests to be combined more naturally with conditional syntax. e.g. if (have(SOME_FEATURE) && have(SOME_OTHER_FEATURE) && featureData != NULL) { use_the_features(featureData); } ## Config.h #ifndef CONFIG_H #define CONFIG_H /* Current configuration */ #include "Config.inc" /** * Build-time configuration test. * e.g. if (have(SOME_FEATURE)) use_some_feature(); * * Default build-time configuration is defined in Config.inc. * * @param C Configuration feature to test */ #define have(C) HAVE_##C() /* ======================================================================== */ /* Configuration rules */ /* ======================================================================== */ /* Release features */ #if defined CONFIG_RELEASE #define CONFIG_FEATURE_A #undef CONFIG_FEATURE_B #endif /* Default features */ #if defined CONFIG_DEFAULT #define CONFIG_FEATURE_A #endif /* Maximum code coverage */ #if defined CONFIG_ALL #define CONFIG_FEATURE_A #define CONFIG_FEATURE_B #endif /* ======================================================================== */ /* Configuration convenience macros. */ /* ======================================================================== */ /* Set: Enable feature A * Unset: Disable feature A * Depends: no dependent features */ #if defined CONFIG_FEATURE_A #define HAVE_CONFIG_FEATURE_A() (1) #else #define HAVE_CONFIG_FEATURE_A() (0) #endif /* Set: Enable feature B * Unset: Disable feature B * Depends: no dependent features */ #if defined CONFIG_FEATURE_B #define HAVE_CONFIG_FEATURE_B() (1) #else #define HAVE_CONFIG_FEATURE_B() (0) #endif #endif /* CONFIG_H */ ## Config.inc /* * Default build-time configuration. * See Config.h * */ #define CONFIG_DEFAULT # Notes Variables that a feature depends on are either unused or would still need to be excluded from compilation with #ifdef. Or better, refactor the feature and its variables into their own compilation unit. <!-- vim: filetype=markdown -->
Uploading file...
Sidebar
# SideBar * [Home][1] * [Projects][2] * * * <!-- --> * [Code][3] * [Tech][4] * [Network][5] * [MediaCentre][6] * [UAV][7] * * * <!-- --> * [Travel][8] * [Music][9] * [Horse Riding][10] * [Study][11] * [Games][12] * [Other Activities][13] * * * <!-- --> * [Car][14] * [House][15] * [Watch][16] * [Clothing][17] * [Miscellany][18] * * * [1]: /Home [2]: /Projects [3]: /Code/Code [4]: /Tech/Tech [5]: /Network/Network [6]: /MediaCentre/MediaCentre [7]: /UAV/UAV [8]: /Travel/Travel [9]: /Music/Music [10]: /HorseRiding/HorseRiding [11]: /Study/Study [12]: /Games/Games [13]: /Do/Do [14]: /Car/Car [15]: /House/House [16]: /Watch/Watch [17]: /Clothing/Clothing [18]: /Miscellany/Miscellany <!-- vim: filetype=markdown -->
Edit message:
Cancel