home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!vtserf!csugrad!lkestel
- From: lkestel@csugrad.cs.vt.edu (Lawrence Kesteloot)
- Newsgroups: alt.hackers
- Subject: Re: Stupid macro tricks...
- Message-ID: <C1E75L.7J9@csugrad.cs.vt.edu>
- Date: 25 Jan 93 04:29:44 GMT
- References: <C1DnqE.L3u@mentor.cc.purdue.edu>
- Distribution: alt
- Organization: Virginia Tech Computer Science Dept, Blacksburg, VA
- Lines: 51
- Approved: shoot your dog
-
- daffnelr@mentor.cc.purdue.edu (Throatwarbler Mangrove) writes:
-
-
- > Hey.. anyone out there got really
- >ugly/complicated/elegant/interesting macros in any of their programs?
-
- This isn't actually my own program, but it's ugly enough that I thought
- you might like to see it. It's from BSD Net/2, from the kernel malloc
- source code:
-
- /*
- * Copyright (c) 1987 Regents of the University of California.
- * All rights reserved.
- */
-
- #define BUCKETINDX(size) \
- (size) <= (MINALLOCSIZE * 128) \
- ? (size) <= (MINALLOCSIZE * 8) \
- ? (size) <= (MINALLOCSIZE * 2) \
- ? (size) <= (MINALLOCSIZE * 1) \
- ? (MINBUCKET + 0) \
- : (MINBUCKET + 1) \
- : (size) <= (MINALLOCSIZE * 4) \
- ? (MINBUCKET + 2) \
- : (MINBUCKET + 3) \
- : (size) <= (MINALLOCSIZE* 32) \
- ? (size) <= (MINALLOCSIZE * 16) \
- ? (MINBUCKET + 4) \
- : (MINBUCKET + 5) \
- : (size) <= (MINALLOCSIZE * 64) \
- ? (MINBUCKET + 6) \
- : (MINBUCKET + 7) \
- : (size) <= (MINALLOCSIZE * 2048) \
- ? (size) <= (MINALLOCSIZE * 512) \
- ? (size) <= (MINALLOCSIZE * 256) \
- ? (MINBUCKET + 8) \
- : (MINBUCKET + 9) \
- : (size) <= (MINALLOCSIZE * 1024) \
- ? (MINBUCKET + 10) \
- : (MINBUCKET + 11) \
- : (size) <= (MINALLOCSIZE * 8192) \
- ? (size) <= (MINALLOCSIZE * 4096) \
- ? (MINBUCKET + 12) \
- : (MINBUCKET + 13) \
- : (size) <= (MINALLOCSIZE * 16384) \
- ? (MINBUCKET + 14) \
- : (MINBUCKET + 15)
-
- ObHack: Porting Net/2 to the Mac (works quite well, thank you).
-
- Lawrence
-