home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!olivea!spool.mu.edu!sdd.hp.com!think.com!spdcc!dirtydog.ima.isc.com!karl
- From: karl@ima.isc.com (Karl Heuer)
- Newsgroups: comp.lang.c
- Subject: Re: Sets in C
- Message-ID: <1992Sep11.230445.5940@ima.isc.com>
- Date: 11 Sep 92 23:04:45 GMT
- References: <14390@goanna.cs.rmit.oz.au> <kjb.716185475@godzilla.cgl.citri.edu.au> <1992Sep11.165838.3382@taumet.com>
- Sender: usenet@ima.isc.com (news)
- Organization: Interactive Systems, Cambridge, MA 02138-5302
- Lines: 27
-
- In article <1992Sep11.165838.3382@taumet.com> steve@taumet.com (Steve Clamage) writes:
- >The C Standard allows an implementation to restrict the size of
- >bitfields to the size of an int.
-
- This is true, and possible a correct response to the immediate parent of your
- article, but somewhere along the thread some confusion seems to have seeped
- in. The original article was asking about implementing sets, and oversized
- bitfields wouldn't address that anyway.%
-
- It *is* true that you can have more than 32 single-bit fields in a struct, and
- this would be a way to implement sets as long as you only need to test for
- constants:
- struct FruitBasket { unsigned apple : 1; unsigned orange : 1; ... };
-
- But since it's illegal to have bitfield arrays (sigh), I think it's more
- likely that one or more of the people who used the term "bitfield" were
- actually talking about doing the operations on ints:
- typedef unsigned long Set;
- #define test(s, x) (((s) & (1<<(x))) != 0)
-
- I believe it's already been noted that this model can be extended to sets over
- a larger universe by using an array of an integral type.
-
- Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
- ________
- % Unless someone is incorrectly assuming that struct{int:100} would give you
- a BigNum that you could shift and mask like a normal-sized int.
-