c++ - Eliminating unused data
- Nicolay Haustov (20/20) Aug 15 2003 Are there any options that will cause dmc not to generate string constan...
- Winfried Mevenkamp (15/15) Aug 15 2003 Try using a macro like this
- Nicolay Haustov (35/36) Aug 18 2003 Thanks for the response.
- Ilya Minkov (2/26) Aug 15 2003
- Nicolay Haustov (6/7) Aug 18 2003 Thanks for response.
Are there any options that will cause dmc not to generate string constants when they are not used? In my project, I have lots of debugging code, which is all gone for release builds, but debugging messages are still present in final executable. I.e. I want "Hello, world." not to be generated from the following program(simplified). #ifdef LOGGING void log(const char *s) { printf("%s\n"); } #else inline void log(const char *s) { } #endif int main() { log("Hello, world"); return 0; }
Aug 15 2003
Try using a macro like this #define LOGGING 1 #ifdef LOGGING #define TRACE printf #else #define TRACE 1 ? (void)0 : printf #endif int main(int argc, char* argv[]) { for (int n = 0; n < argc; n++) TRACE("Hello, world, argv[%d] = %s\n", n, argv[n]); return 0; } HTH Winfried
Aug 15 2003
In article <bhisbv$2o3i$1 digitaldaemon.com>, Winfried Mevenkamp says...Try using a macro like thisThanks for the response. As always, real world case is more complex. I need to log different data, including my own classes. I am using C++ operator <<, something like this, again simplified. Using macro here would mean uglifying code, but looks like I will have to do it... class logger {}; class A {}; #ifdef LOGGING logger& operator<<(logger& log, const char *s) { printf("%s\n", s); return log; } logger& operator<<(logger& log, const A& a) { printf("A\n"); return log; } #else inline logger& operator<<(logger& log, const char *s) { return log; } inline logger& operator<<(logger& log, const A& a) { return log; } #endif int main() { logger log; log << "Hello, world!" << A(); return 0; }
Aug 18 2003
You may want to look up function-level linkage in the manual. Nicolay Haustov wrote:Are there any options that will cause dmc not to generate string constants when they are not used? In my project, I have lots of debugging code, which is all gone for release builds, but debugging messages are still present in final executable. I.e. I want "Hello, world." not to be generated from the following program(simplified). #ifdef LOGGING void log(const char *s) { printf("%s\n"); } #else inline void log(const char *s) { } #endif int main() { log("Hello, world"); return 0; }
Aug 15 2003
In article <bhj0tt$2s1a$2 digitaldaemon.com>, Ilya Minkov says...You may want to look up function-level linkage in the manual.Thanks for response. I had a feeling that this option(-Nc) only helps eliminate unused functions. This is not a problem: all debugging code is gone from final executable. However, all debug messages are still present. And indeed, it seems to have no effect(just tried).
Aug 18 2003