Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #162934

Re: redeclaration of enumerators?

From Bart <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: redeclaration of enumerators?
Date 2021-10-02 12:16 +0100
Organization A noiseless patient Spider
Message-ID <sj9f3d$4v1$1@dont-email.me> (permalink)
References (9 earlier) <87tui2j1m3.fsf@nosuchdomain.example.com> <sj44gi$odk$1@dont-email.me> <bf3ac5ed-f44b-4f8d-9ffe-ad9583ade948n@googlegroups.com> <sj6csf$dvm$1@dont-email.me> <sj6nkg$4am$1@dont-email.me>

Show all headers | View raw


On 01/10/2021 11:24, Bart wrote:
> On 01/10/2021 08:20, David Brown wrote:

>> typedef enum Colours { red, green, blue } Colours;
>>
>> extern const char * const colour_names[];
>> const char * const colour_names[] = {
>>      [red] = "red",
>>      [green] = "green",
>>      [blue] = "blue",
>> };
> 

> However I do use this feature:
> 
>     tabledata() []ichar colour_names =
>        (red,      $),
>        (green,    $),
>        (blue,     $),
>     end

I know this will intensely annoy David Brown, so I suggest he doesn't 
read further.

Below is a real example of such a set of enums from some old project of 
mine.

Here's a C X-macro version for comparison, partly populated:

   #define COLOURTABLE \
    COL(black, 00,00,00) \
    COL(red,   00,00,C0) \
    COL(white, FF,FF,FF) \


   enum colours {
   #define COL(name,b,g,r) \
      name,
   COLOURTABLE
   #undef COL
   };

   char* coloursnames[] = {
   #define COL(name,b,g,r) \
      #name,
   COLOURTABLE
   #undef COL
   };

   unsigned int coloursvalues[] = {
   #define COL(name,b,g,r) \
      0x##b##g##r,
   COLOURTABLE
   #undef COL
   };


Lovely. However, while my version below is automatically visible to all 
modules that bother to import this one, the C requires some extra 
hackery to share it across modules.

-----------------------------------------

   global tabledata() colournames, colourvalues =
   !                    BB'GG'RR
     (black,     $,  0x_00'00'00),

     (red,       $,  0x_00'00'C0),
     (dkred,     $,  0x_00'00'90),
     (red3,      $,  0x_00'00'70),

     (green,     $,  0x_00'C0'00),
     (dkgreen,   $,  0x_00'90'00),
     (green3,    $,  0x_00'70'00),

     (blue,      $,  0x_C0'00'00),
     (dkblue,    $,  0x_90'00'00),
     (blue3,     $,  0x_70'00'00),

     (cyan,      $,  0x_c0'c0'00),
     (dkcyan,    $,  0x_90'90'00),
     (cyan3,     $,  0x_70'70'00),

     (magenta,   $,  0x_c0'00'c0),
     (dkmagenta, $,  0x_90'00'90),
     (magenta3,  $,  0x_70'00'70),

     (yellow,    $,  0x_00'C0'C0),
     (dkyellow,  $,  0x_00'90'90),
     (yellow3,   $,  0x_00'70'70),
     (yellow4,   $,  0x_00'50'50),

     (white,     $,  0x_FF'FF'FF),
     (ltgrey,    $,  0x_C0'C0'C0),
     (grey,      $,  0x_90'90'90),
     (dkgrey,    $,  0x_70'70'70),

     ....
   end

(Example is from dynamic code. Static code would be identical, except 
that types are needed:

   global tabledata() []ichar colournames, []ichar colourvalues =

)

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

redeclaration of enumerators? Thiago Adams <thiago.adams@gmail.com> - 2021-09-27 10:39 -0700
  Re: redeclaration of enumerators? John Bode <jfbode1029@gmail.com> - 2021-09-28 16:21 -0500
    Re: redeclaration of enumerators? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-28 14:57 -0700
      Re: redeclaration of enumerators? Thiago Adams <thiago.adams@gmail.com> - 2021-09-28 15:23 -0700
        Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-09-29 15:23 +0200
        Re: redeclaration of enumerators? Mark Bluemel <mark.bluemel@gmail.com> - 2021-09-30 01:15 -0700
      Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-09-28 23:31 +0100
        Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-09-29 15:36 +0200
          Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-09-29 15:03 +0100
            Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-09-29 16:46 +0200
              Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-09-29 16:08 +0100
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-09-29 20:14 +0200
                Re: redeclaration of enumerators? Thiago Adams <thiago.adams@gmail.com> - 2021-09-29 13:37 -0700
                Re: redeclaration of enumerators? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-29 18:25 -0700
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-09-30 12:45 +0200
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-09-30 07:36 -0700
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-10-01 09:20 +0200
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 11:24 +0100
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-10-01 04:49 -0700
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 13:06 +0100
                Re: redeclaration of enumerators? Tony Oliver <guinness.tony@gmail.com> - 2021-10-01 05:24 -0700
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 13:32 +0100
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-10-01 05:32 -0700
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 13:43 +0100
                Re: redeclaration of enumerators? Mark Bluemel <mark.bluemel@gmail.com> - 2021-10-01 06:13 -0700
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-10-01 06:29 -0700
                Re: redeclaration of enumerators? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-01 15:30 +0100
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-10-01 08:28 -0700
                Re: redeclaration of enumerators? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-10-01 17:08 +0100
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-10-01 15:12 -0700
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-10-01 15:37 +0200
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 15:30 +0100
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-10-01 19:12 +0200
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 19:06 +0100
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-10-01 15:32 +0200
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 15:38 +0100
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-01 17:40 +0100
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-02 12:16 +0100
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-10-02 15:34 +0200
                Re: redeclaration of enumerators? Bart <bc@freeuk.com> - 2021-10-02 15:16 +0100
                Re: redeclaration of enumerators? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-10-01 13:58 -0700
                Re: redeclaration of enumerators? Richard Damon <Richard@Damon-Family.org> - 2021-10-01 17:21 -0400
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-10-01 14:56 -0700
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-10-02 12:21 +0200
                Re: redeclaration of enumerators? scott@slp53.sl.home (Scott Lurndal) - 2021-09-30 14:47 +0000
                Re: redeclaration of enumerators? Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-09-30 10:10 -0700
                Re: redeclaration of enumerators? David Brown <david.brown@hesbynett.no> - 2021-10-01 09:24 +0200
            Re: redeclaration of enumerators? Andrey Tarasevich <andreytarasevich@hotmail.com> - 2021-09-29 12:43 -0700
    Re: redeclaration of enumerators? Branimir Maksimovic <branimir.maksimovic@gmail.com> - 2021-09-29 03:40 +0000

csiph-web