Shared publicly  - 
 
 
Hey, since the last disgusting code hack thing worked out so well on G+, here's a new challenge..

Improve on this new disgusting hack:

#define is_enabled(x) (__stringify(CONFIG_##x)[0]=='1')

which basically is a C language "is the config variable 'x' defined" question (the "__stringify()" thing is the normal two-level macro expansion using the '#' operator, so that it expands the macro argument and then turns it into a string). And gcc does seem to do the proper compile-time optimizations that turn the above into a simple constant.

The intent is to be able to write

if (is_enabled(PROC)) {
...

in C code, without having to make ugly #ifdef sections with all the odd line breaks etc that entails. The kernel config rules are that the CONFIG_XYZ macro exists and has the value '1' for enabled features (you can ignore the module case for now - that's just the same thing, except the preprocessor name is CONFIG_XYZ_MODULE)

Is there a better trick for this? Bonus points if somebody comes up with a single macro that works for both C code and in pre-processor expressions.
1
Add a comment...