Converting enums to pointers

From: James Aguilar (
Date: 10/11/04

Date: Sun, 10 Oct 2004 20:06:49 -0500

I have a class that's holding a list of pointers to pointers. It is an
implementation of an open addressed hashmap. It is homework, but I only
want help on this specific issue. Please do not tell me anything about
hashmaps, just about this small problem. Suppose I want to have an
enumeration that describes various states that a slot can have besides
having contents.

enum SpecStates { EMPTY = 0, DELETED = -1 };

However, the array that holds the information is an array of 'Record*'s. I
cannot assign EMPTY or DELETED to a slot without an explicit type cast (
(Record*) EMPTY ), since it involves a jump from int to Record*, which is
taken to be from int to void* to Record*. This is ugly and, perhaps,

I have also considered

const Record* EMPTY = (Record*) 0;
const Record* DELETED = (Record*) 1;

But if I do that I have lost all the convenience of the enumerated type.

What is the correct way to accomplish what I am trying to do, assuming I
want no major design changes (for instance, I want no wrapper for the
Record, since, although that would work, it does not preserve the simplicity
I am seeking)?


Relevant Pages

  • Re: sysadmin qualifications (Re: apt-get vs. aptitude)
    ... I liked them too, at a time, but since I can now use standard ... pointers in C++, ... Because I know that an int can be stored into one ... I expect it to contains printable characters, not the equivalent to an int. ...
  • Re: A taxonomy of types
    ... I am describing how to represent the representation (and, ... if the system follows static typing rules (such as in a compiler), ... so, the hardware sees pointers and pointer arithmetic, but the compiler ... "Besides the char types, up to three sizes of integer, declared short int, ...
  • Re: Malloc code
    ... int xxx; ... As for not using the void pointer, I will have to do some further testing ... I just needed some insight on passing arrays of pointers. ... struct MCB *r1; ...
  • I want my segmentation fault!
    ... no occurrences of free and a lot of routines returning pointers to ... the pointer returned by the allocator (either directly or as a component ... int length_of_list; ...
  • Re: Simple question, err... I think
    ... Your nodes contain no other indication of which pointers are valid, ... struct CountedObject ... int is_red; ... bool lament(char const s) ...