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


Groups > comp.lang.c > #18919

Re: reusing identifier in two enums

From jgk@panix.com (Joe keane)
Newsgroups comp.lang.c
Subject Re: reusing identifier in two enums
Date 2012-03-21 02:45 +0000
Organization Public Access Networks Corp.
Message-ID <jkbfc7$ep8$1@reader1.panix.com> (permalink)
References <93a85ab3-ecbf-4aa0-8fbd-6699e810b9e9@v2g2000vbx.googlegroups.com>

Show all headers | View raw


In article <93a85ab3-ecbf-4aa0-8fbd-6699e810b9e9@v2g2000vbx.googlegroups.com>,
ImpalerCore  <jadill33@gmail.com> wrote:
>I have two related but separate enumerations where I'd like to use the
>same identifier to represent an invalid type.

This is basically subtypes which define the valid values, and a
supertype where one can only set an invalid value, and test for that.

class basic_type
{
    static const int invalid = -1;
    int x;

    bool is_valid() const { return x >= 0; }
    void set_invalid() { x = invalid; }
};

class color_type : basic_type
{
    enum color { red = 1, orange = 13, yellow = 3, ... };

    bool is_red() const { return x == red; }
    void set_red() { x = red; }
    ...
};

Decrement the language:

#define BASIC_INVALID_TYPE -1
#define BASIC_TYPE_IS_VALID(X) ((X) >= 0)
#define BASIC_TYPE_SET_INVALID(X) ((X) = BASIC_INVALID_TYPE)

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


Thread

reusing identifier in two enums ImpalerCore <jadill33@gmail.com> - 2012-03-19 08:04 -0700
  Re: reusing identifier in two enums "Morris Keesan" <mkeesan@post.harvard.edu> - 2012-03-19 12:19 -0400
    Re: reusing identifier in two enums ImpalerCore <jadill33@gmail.com> - 2012-03-19 10:43 -0700
  Re: reusing identifier in two enums Keith Thompson <kst-u@mib.org> - 2012-03-19 10:43 -0700
    Re: reusing identifier in two enums ImpalerCore <jadill33@gmail.com> - 2012-03-19 11:42 -0700
  Re: reusing identifier in two enums jgk@panix.com (Joe keane) - 2012-03-21 02:45 +0000
    Re: reusing identifier in two enums Jens Gustedt <jens.gustedt@loria.fr> - 2012-03-21 17:04 +0100

csiph-web