Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site sjuvax.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!princeton!astrovax!sjuvax!jss From: jss@sjuvax.UUCP (J. Shapiro) Newsgroups: net.lang.c Subject: Re: places where sets are useful Message-ID: <923@sjuvax.UUCP> Date: Tue, 5-Mar-85 01:38:29 EST Article-I.D.: sjuvax.923 Posted: Tue Mar 5 01:38:29 1985 Date-Received: Wed, 6-Mar-85 14:06:21 EST References: <10983@watmath.UUCP> <21000020@uiucuxc.UUCP> Organization: Saint Josephs Univ. Phila., Pa. Lines: 60 >> type >> mymodes = (insert, error, append, ...); >> var >> status = set of mymodes; >> begin >> ... >> if (status * [insert, append]) <> [] then begin.... >> ... >> end >> ... >I agree. Here's how I would write this in C: > >enum {insert, error, append, ... }; >#define elem(n) (1 << (int)(n)) >short status; >... > if (status & (elem(insert) | elem(append))) { > ... > /* add 'error' to set 'status' */ > status |= elem(error); > > /* remove 'error' from set 'status' */ > status &= ~elem(error); As the original poster, I thought I had said that enums are problematic because many compilers don't support them. Also, this leaves one with the limit that the number of elements of the set must be <= number of bits in a long. It has been suggested that this is equally much a problem in pascal, but in reality every compiler I have worked with handles the code extensions automatically. Why should the programmer be obliged to write his own bitfield manipulation code when this is something the compiler could (and in pascal does) do perfectly well for itself. I am all in favor of hands on control, but only where doing the work yourself really buys you something. Any compiler which generates worse code than I do by hand to handle large bitsets is making a concerted effort to generate bad code. Incidentally, many people provided macros that handle everything for sets which can be described with the number of bits in a long. *All* of them said that "extending this for longer sets is trivial." No one to date has bothered to cough up code I believe (with one exception - but I would need to go searching my mailbox to find out who). If C is really so adequate to do the job, would somebody cough up a working set of macros (or a preprocessor - which I believe is the necessary item) which: a) all of us will agree to use b) all of us will be satisfied with as something to augment the language. c) will be useable with any C compiler (excludes enums...) I can't think of anything which meets all of these qualifications.... I hope I am wrong ;-) Jon Shapiro happily provided