Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #387946
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: enum sets |
| Date | 2024-08-28 17:30 -0700 |
| Organization | None to speak of |
| Message-ID | <871q28b26c.fsf@nosuchdomain.example.com> (permalink) |
| References | <vaoclb$3lfbf$1@dont-email.me> |
Thiago Adams <thiago.adams@gmail.com> 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 */
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
enum sets Thiago Adams <thiago.adams@gmail.com> - 2024-08-28 20:42 -0300
Re: enum sets Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-08-28 17:30 -0700
Re: enum sets Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2024-08-28 17:33 -0700
Re: enum sets Kaz Kylheku <643-408-1753@kylheku.com> - 2024-08-29 01:31 +0000
Re: enum sets Thiago Adams <thiago.adams@gmail.com> - 2024-08-29 08:23 -0300
Re: enum sets David Brown <david.brown@hesbynett.no> - 2024-08-29 09:33 +0200
Re: enum sets Thiago Adams <thiago.adams@gmail.com> - 2024-08-29 08:34 -0300
Re: enum sets Thiago Adams <thiago.adams@gmail.com> - 2024-08-29 08:44 -0300
Re: enum sets Blue-Maned_Hawk <bluemanedhawk@invalid.invalid> - 2024-08-29 13:55 +0000
Re: enum sets David Brown <david.brown@hesbynett.no> - 2024-08-29 21:43 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 10:18 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 10:25 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 10:32 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 11:29 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 11:44 +0200
Re: enum sets Thiago Adams <thiago.adams@gmail.com> - 2024-08-29 08:37 -0300
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 14:02 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 14:10 +0200
Re: enum sets Bonita Montero <Bonita.Montero@gmail.com> - 2024-08-29 10:30 +0200
Re: enum sets Thiago Adams <thiago.adams@gmail.com> - 2024-08-29 08:38 -0300
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 15:09 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 15:23 +0200
Re: enum sets Thiago Adams <thiago.adams@gmail.com> - 2024-08-29 10:35 -0300
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 15:51 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 16:09 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 16:18 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 20:16 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 20:38 +0200
Re: enum sets fir <fir@grunge.pl> - 2024-08-29 15:37 +0200
csiph-web