Deutsch   English   Français   Italiano  
<vaptfo$3vten$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Thiago Adams <thiago.adams@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: enum sets
Date: Thu, 29 Aug 2024 10:35:51 -0300
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <vaptfo$3vten$1@dont-email.me>
References: <vaoclb$3lfbf$1@dont-email.me>
 <3be5b29ade1ce269874ab1ef8abf1bd666a7fc9c@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 29 Aug 2024 15:35:52 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f80b8b85f3cf443035f3bd640f6489b4";
	logging-data="4191703"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19KHAg/XlooJCxrQ2E9rkeRi55M8x2wsOI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:igjer2PzYuu5TbkAuJxGP8tn874=
Content-Language: en-US
In-Reply-To: <3be5b29ade1ce269874ab1ef8abf1bd666a7fc9c@i2pn2.org>
Bytes: 3193

On 29/08/2024 10:09, fir wrote:
> Thiago Adams wrote:
>> 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.
>>
>>
> reading yet once i dont know what you want
> 
> i guess you maybe say what i understand as kinda "micro dictionary"
> 


It does not use bits. Each enumerator will have a sequential number 
like it is today.

When the same enumerator is used twice the number does not change.

Sample:

enum font_type
{
      enum monospaced_font_type
      {
          CASCADIA_FONT,
      },

      ARIAL_FONT,

      enum modern_monospaced_font_type
      {
          CASCADIA_FONT,
      },
  };



CASCADIA_FONT is 0
ARIAL_FONT is 1



The implementation could work like this:

Each enum has a set of "parent enums."

A cast or conversion from one enum to another will trigger a warning if 
the target type is not in the parent set.

For instance, casting from enum monospaced_font_type to enum font_type 
is fine because the parent set of enum monospaced_font_type is { enum 
font_type }.

Each enumerator will also have its own parent set, representing the 
enums it belongs to. For example, CASCADIA_FONT belongs to { enum 
monospaced_font_type, enum font_type } .

Therefore, converting an enumerator to any enum in its parent set is 
acceptable; otherwise, a warning will be issued.

In a switch case for an enum type, we must ensure that all enumerators 
of that type are present.

For example, in a switch statement for enum font_type, we need to check 
that all enumerators with enum font_type in their parent set are included.