Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
August 15, 2003 Eliminating unused data | ||||
---|---|---|---|---|
| ||||
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; } |
August 15, 2003 Re: Eliminating unused data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicolay Haustov | 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 |
August 15, 2003 Re: Eliminating unused data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nicolay Haustov | 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;
> }
>
>
|
August 18, 2003 Re: Eliminating unused data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Winfried Mevenkamp | In article <bhisbv$2o3i$1@digitaldaemon.com>, Winfried Mevenkamp says... >Try using a macro like this Thanks 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; } |
August 18, 2003 Re: Eliminating unused data | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Minkov | 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). |
Copyright © 1999-2021 by the D Language Foundation