4 ms·
This will compile to different things depending on whether you are using a C or a C++ compiler. Worse, it may compile to different things depending on which st
by coherentpony 14y ago
This will compile to different things depending on whether you are using a C or a C++ compiler. Worse, it may compile to different things depending on which standard you compile to. If you don't want you colleagues to hate you, you should probably use:
#ifdef DEBUG
testCode();
#else
productionCode();
#endif
Or, better yet, if it really is test code then write a test.
- shubb 14y agoI don't understand why someone would do this nested comments thing. This is what macro block are for... And tests need to be separated from the code. Hopefully using a test framework. If your code changes depending on if it is in 'test mode' or not (which is what is proposed), then the test code is not the same as the production code, i.e. the production code is not tested. I'm not just talking about timing issues - extra variable names and objects will be in scope in 'test mode', and might logically change the behavior of the program.
- alexanderbrevig 14y ago* not all languages have macros * you don't use test frameworks for enabling and disabling code inline while you're developing Please read the protip, understand my intention (keyword TRICK) and have a delightful cup of coffee. You've earned it.
- B-Con 14y agoWelcome to Hacker News. :-) > understand my intention We don't do that here. However, we do have an unparalleled menu of pedantic critique, edge case obsession, and a wonderful sauce made from insanely perfect standards.