From ripley at stats.ox.ac.uk  Wed Mar 16 00:49:11 2005
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Wed Mar 16 00:49:21 2005
Subject: [Rd] How to store void* on 64 bit machines
In-Reply-To: <C698D707214E6F4AB39AB7096C3DE5A58FF422@phost015.EVAFUNDS.intermedia.net>
References: <C698D707214E6F4AB39AB7096C3DE5A58FF422@phost015.EVAFUNDS.intermedia.net>
Message-ID: <Pine.LNX.4.61.0503152342400.17975@gannet.stats>

On Tue, 15 Mar 2005, Vadim Ogranovich wrote:

> I have an R class which represents a file stream (this is my custom
> implementation of R I/O and has nothing to do with the standard R
> connections). The class has a slot, called id, which is essentially a
> void* pointer to a C++ stream object.
>
> Up until now I worked on 32-bit machines and the id slot was an integer,

If by `slot' you mean the slot in an S4 class, that is not correct.
R has integer vectors, not integer scalars.

> so one could cast back and forth between int and void*. However, on
> 64-bits void* is castable to 'long int', but not int, which poses a
> couple of problems:
> a) since there is no R arrays of 'long int' type what other built-in
> type can I use to store void*. For example double is big enough to
> accommodate void*, but I am not sure whether casting will work both
> ways.
>
> b) assuming that a) is solvable, is there a solution which is portable
> between 64 and 32 bit machines?

The raw type can store anything: your pointer is just a stream of bytes.
It could also be stored as one or two integers.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


[Rd] How to store void* on 64 bit machines
Prof Brian Ripley