Path: ...!npeer.as286.net!npeer-ng0.as286.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: enum sets Date: Wed, 28 Aug 2024 17:30:51 -0700 Organization: None to speak of Lines: 44 Message-ID: <871q28b26c.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Date: Thu, 29 Aug 2024 02:30:51 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d17aacdbc8a710bbcdf54ea5a7e9baf3"; logging-data="3842266"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1GvZLVCefH/Vl7rrXBcZ8" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:YtMS6Z+E5vykN/D9sVdozvX/BDY= sha1:WmU0I+TueTq7QTvsdiInljF39ow= Bytes: 2325 Thiago Adams writes: > I am wondering how useful would be to have enum sets. > > Let´s say you have a function that accepts only monospaced fonts.Then > you can use enum monospaced_font_type. Or a switch case where you need > to check all and only monospaced_font_type. > > But at same type you can store at same object monospaced_font_type or > font_type. > > enum font_type > { > enum monospaced_font_type > { > CASCADIA_FONT, > }, > ARIAL_FONT > }; > > This could be arranged in any way. If I understand you correctly, enum monospaced_font_type is a *subtype* of enum font_type. Ada has something very similar to this: type Font_Type is (CASCADIA_FONT, ARIAL_FONT); subtype monospaced_font_type is Font_type range CASCADIA_FONT .. CASCADIA_FONT; An Ada subtype is a type with an optionally added *constraint*, which can be checked at runtime. But it's hard to see how you'd add this to C. Given your type definition, how would this behave? void func(enum monospaced_font_type); enum font_type font = ARIAL_FONT; func(font); (The Ada equivalent would raise a run-time exception.) -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */