and write functions like:
void fct (void) {
if (debug.input) printf ("input is: ...");
}
So that the debug code is completely removed when debug is null,
without #ifdef, and variables only used when debug.input is set
do not need an #ifdef too to remove warnings "set but not used"...
Posted Apr 8, 2011 17:51 UTC (Fri) by dtlin (✭ supporter ✭, #36537)
[Link]
Doesn't GCC already do that (at least under some optimization levels)?
GCC 4.6.0 released
Posted Apr 11, 2011 12:27 UTC (Mon) by etienne (subscriber, #25256)
[Link]
GCC treat const variable as thing which cannot be modified by the code, i.e. more like read-only.
You can modify the const variable in assembler, or in another piece of code where that variable is not declared "const".
Long time ago I read that you could use "static const" in C++ to get the same behaviour but I then tried and the variable was still defined as a piece of memory - and that was not available to C.
What I would like is that no memory is ever reserved for "inline const struct {}" - so the tests are always either true or false at compilation time, address of that variable cannot be taken, etc...
GCC 4.6.0 released
Posted Apr 11, 2011 20:05 UTC (Mon) by jrn (subscriber, #64214)
[Link]
const register? constexpr?
GCC 4.6.0 released
Posted Jul 18, 2011 10:03 UTC (Mon) by runciter (guest, #75370)
[Link]
It's constant, doesn't use any memory and doesn't use the preprocessor.
GCC 4.6.0 released
Posted Jul 18, 2011 13:12 UTC (Mon) by etienne (subscriber, #25256)
[Link]
But it is not as "structured" as a C structure named "debug" which would contain not only boolean but where to send the ouput (stdout, stderr, serial, filename...) and sub-structures like what to debug in "INPUT".
Anyway GCC-4.6 does introduce the inlining of constants, if you want a read only variable modified in the ELF file or at assembly time before main() is called, you now need to use "volatile const" - I was too quick to do that initial comment...