Re: Converting enums to pointers

From: Rolf Magnus (ramagnus_at_t-online.de)
Date: 10/11/04


Date: Mon, 11 Oct 2004 12:02:41 +0200

Ron Natalie wrote:

> James Aguilar wrote:
>
>> const Record* EMPTY = (Record*) 0;
>
> You declare EMPTY to be a null pointer here. This is legitimate.

Yes, and it doesn't actually need a cast.

>> const Record* DELETED = (Record*) 1;
>
> This is implementation defined and may not universally work. Nothing
> guarantees you can reinterpret cast an arbitrary integer to a pointer
> type.

And nothing guarantess that the resulting pointer value is not one that
points to an existing object.

>> But if I do that I have lost all the convenience of the enumerated type.
>>
> const Record DELETED;
> would work, of course it allocates an unused Record object.



Relevant Pages