Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utcs!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP Newsgroups: net.sources.d Subject: Re: ifdef filter Message-ID: <2496@umcp-cs.UUCP> Date: Sat, 19-Jul-86 20:23:41 EDT Article-I.D.: umcp-cs.2496 Posted: Sat Jul 19 20:23:41 1986 Date-Received: Sat, 19-Jul-86 23:38:51 EDT References: <323@enmasse.UUCP> <924@cyb-eng.UUCP> Reply-To: chris@maryland.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 48 In article <323@enmasse.UUCP> someone writes: >It often happens that software packages are set up to run on so many >configurations that it is hard to read the code because of all the >ifdefs. ... That is, filter out everything that is not going to be >expanded by cpp while retaining the ifdefs that are going to be expanded, >just for comment value. I can understand the desire for this: reading code before using it is often a good idea. However, I am not at all convinced that this is a good way to make the code more readable. I have run into this `ifdef problem' in the past, and the best solution I have come up with so far is to properly group the dependencies and to construct system-independent routines or `define's so that no further `if's are required: #ifdef xyzzy #define strchr index #define strrchr rindex #define input_pending(fd) funny_system_call(fd) #else /* xyzzy */ #define input_pending(fd) routine_to_do_input_pending(fd) #endif /* xyzzy */ #if defined(a) || defined(b) #define memcpy(d, s, n) bcopy(s, d, n) #endif /* a || b */ #ifdef gleep routine() /* for gleep */ { ... } #else /* gleep */ routine() /* for everyone else */ { ... } #endif /* gleep */ and so forth. Of course, doing this to an existing program is much more difficult than simply weeding out irrelevant `ifdef's. It does, however, maintain portability. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1516) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu