Community

Hello,
I wrote a container that relies on treating two different values in a
special way (they are used as some kind of flag).
For a container of integers, I just use 0 and 1 as special elements.
Those special entries are for internal use only.
The problem comes when I extend the container for reference types.
Instead of 0 I use null, but for 1 the trouble begins.
Is it possible to circumvent the type system and convert an integer to a
pointer or class type? They won't ever be dereferenced, of course.
Many would probably think that this is the wrong way anyway,
but I try to avoid memory usage that way and to increase speed.
Introducing special workarounds also make the code more complicated.

On Sun, 29 Jun 2008 04:05:02 +0200, Mike wrote:
> On Sun, 29 Jun 2008 03:35:03 +0200, Moritz Warning
> <moritzwarning@web.de> wrote:
>
>> Is it possible to circumvent the type system and convert an integer to
>> a pointer or class type? They won't ever be dereferenced, of course.
>
> union
> {
> int integer;
> void *pointer;
> }
Would work probably.
But I found another solution using a static and alias to fit in two base
types quite nicely. (size_t and void*)