dkhusema@immd4.informatik.uni-erlangen.de (Dirk Husemann) (07/17/89)
ast@cs.vu.nl (Andy Tanenbaum) writes: >In article <19654@louie.udel.EDU> V61%DHDURZ1.BITNET@cunyvm.cuny.edu (Ronald Lamprecht) writes: >>The additional code should >>be included in #ifdef DEBUG -- #endif so that it is possible to generate >>a fast run-time library and a debugging library version. >Argh! I think #ifdefs make code very hard to read and ugly. I am not all >that wild about the idea. How about using the #ifdef-#endif constructs at a different place (header file?) and just put a macro at the appropiate place - doesn't that look nicer? E.g. db.h [header file]: #ifdef DEBUG #define DB2(format, arg1, arg2) /* something to print the args accor- ding to the format string */ #define DB3(format, arg1, arg2, arg3) /* ditto */ ... #else /* DEBUG */ #define DB2(format, arg1, arg2) #define DB3(format, arg1, arg2, arg3) ... #endif /* DEBUG */ codefile.c [code file]: codecall(msg, count) char *msg; int count; { DB2("codecall(%s, %d)\n", msg, count); ... } I think this wouldn't look too bad, but should do it! How about it? >Andy Tanenbaum (ast@cs.vu.nl) Dirk Husemann ------------------ Smile, tomorrow will be worse! -------------- Email: dkhusema@immd4.informatik.uni-erlangen.de Or: {pyramid,unido}!fauern!immd4.informatik.uni-erlangen.de!dkhusema Mail: Dirk Husemann, Aufsess-Str. 19, D-8520 Erlangen, (Home) West Germany (Busi- University of Erlangen-Nuremberg, Computer Science Dep., ness) IMMD IV, Martensstr. 1, D-8520 Erlangen, West Germany Phone: (Home) +49 9131 302036, (Business) +49 9131 857908 -- Beam me up, Scotty, there's no intelligent life down here! -- --------------- My opinions are mine, mine, mine ---------------
ast@cs.vu.nl (Andy Tanenbaum) (07/18/89)
In article <465@medusa.informatik.uni-erlangen.de> dkhusema@immd4.informatik.uni-erlangen.de (Dirk Husemann) writes: > How about using the #ifdef-#endif constructs at a different place >E.g. >#ifdef DEBUG >#define DB2(format, arg1, arg2) /* something to print the args accor- >#define DB3(format, arg1, arg2, arg3) /* ditto */ >#else /* DEBUG */ I agree that something along those lines would be an improvement. Also, call them DEBUG2 and DEBUG3 instead of DB2 and DB3. Even better is to use assertions. Things like: ASSERT(x < y && z != 0); could be handled by #ifdef DEBUG #define ASSERT(predicate) if (!(predicate)) printf("Assertion error ...\n"); #else #define ASSERT(predicate) /* nothing */ #endif I think assertions have utility as comments even when no code is generated. There is already a file assert.h in V1.3. The only thing wrong with it is that instead of #ifdef DEBUG, it says #ifdef NDEBUG. I think NDEBUG is 10x harder to understand. Andy Tanenbaum (ast@cs.vu.nl)