home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / alt / hackers / 1976 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  1.8 KB

  1. Path: sparky!uunet!vtserf!csugrad!lkestel
  2. From: lkestel@csugrad.cs.vt.edu (Lawrence Kesteloot)
  3. Newsgroups: alt.hackers
  4. Subject: Re: Stupid macro tricks...
  5. Message-ID: <C1E75L.7J9@csugrad.cs.vt.edu>
  6. Date: 25 Jan 93 04:29:44 GMT
  7. References: <C1DnqE.L3u@mentor.cc.purdue.edu>
  8. Distribution: alt
  9. Organization: Virginia Tech Computer Science Dept, Blacksburg, VA
  10. Lines: 51
  11. Approved: shoot your dog
  12.  
  13. daffnelr@mentor.cc.purdue.edu (Throatwarbler Mangrove) writes:
  14.  
  15.  
  16. >  Hey.. anyone out there got really
  17. >ugly/complicated/elegant/interesting macros in any of their programs?
  18.  
  19. This isn't actually my own program, but it's ugly enough that I thought
  20. you might like to see it.  It's from BSD Net/2, from the kernel malloc
  21. source code:
  22.  
  23. /*
  24.  * Copyright (c) 1987 Regents of the University of California.
  25.  * All rights reserved.
  26.  */
  27.  
  28. #define BUCKETINDX(size) \
  29.     (size) <= (MINALLOCSIZE * 128) \
  30.         ? (size) <= (MINALLOCSIZE * 8) \
  31.             ? (size) <= (MINALLOCSIZE * 2) \
  32.                 ? (size) <= (MINALLOCSIZE * 1) \
  33.                     ? (MINBUCKET + 0) \
  34.                     : (MINBUCKET + 1) \
  35.                 : (size) <= (MINALLOCSIZE * 4) \
  36.                     ? (MINBUCKET + 2) \
  37.                     : (MINBUCKET + 3) \
  38.             : (size) <= (MINALLOCSIZE* 32) \
  39.                 ? (size) <= (MINALLOCSIZE * 16) \
  40.                     ? (MINBUCKET + 4) \
  41.                     : (MINBUCKET + 5) \
  42.                 : (size) <= (MINALLOCSIZE * 64) \
  43.                     ? (MINBUCKET + 6) \
  44.                     : (MINBUCKET + 7) \
  45.         : (size) <= (MINALLOCSIZE * 2048) \
  46.             ? (size) <= (MINALLOCSIZE * 512) \
  47.                 ? (size) <= (MINALLOCSIZE * 256) \
  48.                     ? (MINBUCKET + 8) \
  49.                     : (MINBUCKET + 9) \
  50.                 : (size) <= (MINALLOCSIZE * 1024) \
  51.                     ? (MINBUCKET + 10) \
  52.                     : (MINBUCKET + 11) \
  53.             : (size) <= (MINALLOCSIZE * 8192) \
  54.                 ? (size) <= (MINALLOCSIZE * 4096) \
  55.                     ? (MINBUCKET + 12) \
  56.                     : (MINBUCKET + 13) \
  57.                 : (size) <= (MINALLOCSIZE * 16384) \
  58.                     ? (MINBUCKET + 14) \
  59.                     : (MINBUCKET + 15)
  60.  
  61. ObHack: Porting Net/2 to the Mac (works quite well, thank you).
  62.  
  63. Lawrence
  64.