Re: enum sets

Liste des GroupesRevenir à cl c  
Sujet : Re: enum sets
De : fir (at) *nospam* grunge.pl (fir)
Groupes : comp.lang.c
Date : 29. Aug 2024, 16:18:03
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <68f811a783d637cd497edb406367fcbbdb5e7288@i2pn2.org>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (Windows NT 5.1; rv:27.0) Gecko/20100101 Firefox/27.0 SeaMonkey/2.24
fir wrote:
fir wrote:
Thiago Adams wrote:
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.
>
>
ok i guess i undestand what you talkin about
>
you want a list of enums say from 0 to 1703 ordinally on binary level
but but you also want to compiler build a table to which group it belong
but not encode it as bits
>
if so if you want to repeat given emon in more groups than you need to
not give it new walue instead given enum would have two walues
>
it can be done and gives something like more typesafety but the
microdictionary is imo much more interesting idea - as those dictionary
things are in a way fundamental in programming
>
overaly i would said this is good idea - but its generalisation: much
better (could said weird i never thought concretely on this
microdictionaries though i dropped thinking on C for months completely)
i could say i once used something that resembles this dictionary this is gamma table
unsigned char gamma_table[256] =
{
  51,54,60,63,      68,70,73,77,      82,83,84,86,     88,90,92,95,
  98,99,100,101,   102,103,104,106,   108,109,110,111, 113,115,117,120,
  122,122,123,124, 124,125,126,127,  128,129,130,131,  132,133,134,136,
  137,137, 138,139, 140,141,142,143, 144,145,146,147,  148,150,152,153,
  154,154,154,155, 155,155,156,156,  157,157,158,158, 159,159,160,160,
  161,161,161,162, 162,163,163,164,  164,165,166,167, 168,169,170,171,
  172,172,173,173, 174,174,175,175,  176,176,177,177, 178,178,179,179,
  180,180,181,181, 182,182,183,183,  184,185,186,187, 188,189,190,191,
  192,192,192,193, 193,193,194,194,  194,195,195,196, 196,197,197,198,
  198,198,198,199, 199,199,200,200,  201,201,202,202, 203,204,205,206,
  207,207,207,208, 208,208,209,209,  210,210,211,211, 212,212,213,214,
  214,214,214,215, 215,215,216,216,  217,217,218,219, 220,221,222,223,
  224,224,224,225, 225,225,225,226,  226,226,227,227, 228,228,229,229,
  230,230,230,231, 231,231,232,232,  233,233,234,234, 235,235,236,237,
  238,238,238,239, 239,239,240,240,  241,241,242,242, 243,243,244,245,
  246,246,246,247, 247,247,248,248,  249,249,250,251, 252,253,254,255
};
but definig it as such microdictionarry seem to be probably better idea

Date Sujet#  Auteur
29 Aug 24 * enum sets29Thiago Adams
29 Aug 24 +* Re: enum sets4Keith Thompson
29 Aug 24 i+- Re: enum sets1Keith Thompson
29 Aug 24 i+- Re: enum sets1Kaz Kylheku
29 Aug 24 i`- Re: enum sets1Thiago Adams
29 Aug 24 +* Re: enum sets5David Brown
29 Aug 24 i+* Re: enum sets2Thiago Adams
29 Aug 24 ii`- Re: enum sets1Thiago Adams
29 Aug 24 i`* Re: enum sets2Blue-Maned_Hawk
29 Aug 24 i `- Re: enum sets1David Brown
29 Aug 24 +* Re: enum sets8fir
29 Aug 24 i+- Re: enum sets1fir
29 Aug 24 i+- Re: enum sets1fir
29 Aug 24 i+* Re: enum sets2fir
29 Aug 24 ii`- Re: enum sets1fir
29 Aug 24 i`* Re: enum sets3Thiago Adams
29 Aug 24 i `* Re: enum sets2fir
29 Aug 24 i  `- Re: enum sets1fir
29 Aug 24 +* Re: enum sets2Bonita Montero
29 Aug 24 i`- Re: enum sets1Thiago Adams
29 Aug 24 `* Re: enum sets9fir
29 Aug 24  +- Re: enum sets1fir
29 Aug 24  +* Re: enum sets6Thiago Adams
29 Aug 24  i`* Re: enum sets5fir
29 Aug 24  i `* Re: enum sets4fir
29 Aug 24  i  `* Re: enum sets3fir
29 Aug 24  i   `* Re: enum sets2fir
29 Aug 24  i    `- Re: enum sets1fir
29 Aug 24  `- Re: enum sets1fir

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal