Re: pointer -> integer function
Matthew Fluet <[email protected]> Wed, 28 Sep 2016 10:28:39 -0400
| Newsgroups | gmane.comp.lang.ml.mlton.user |
|---|---|
| Message-ID | <CAMrhFL70zTbqoO=+YN2W-+eRd=DN+sWZ4zw1h5KQRrjmbvm3_g@mail.gmail.com> |
You can use the stable, but undocumented, `c-types.mlb` library (https://github.com/MLton/mlton/blob/master/basis-library/c-types.mlb), which provides a collection of structures that correspond to target-dependent C types: mtf@uller tmp]$ cat z.mlb $(SML_LIB)/basis/basis.mlb $(SML_LIB)/basis/mlton.mlb $(SML_LIB)/basis/c-types.mlb z.sml [mtf@uller tmp]$ cat z.sml fun ptrToInt (p: MLton.Pointer.t) : LargeInt.int = C_Size.toLargeInt (C_Pointer.toWord p) Of course, for your application, you might simply use the operations of `structure C_Size : WORD`. On Wed, Sep 28, 2016 at 9:20 AM, Kostirya <[email protected]> wrote: > Hello.I need help again... > > I want to get integer from pointer. > I use (Word.toLargeInt o Primitive.MLton.Pointer.toWord) for 32bit > I use (Word64.toLargeInt o Primitive.MLton.Pointer.toWord) for 64bit > > There are difficulties due to the fact that type function depends on 32bit > or 64bit. > > How to write universal function? > > Like this: > > val p2i = > if sizeofPointer = 0w8 > then Word64.toLargeInt o Primitive.MLton.Pointer.toWord > else Word.toLargeInt o Primitive.MLton.Pointer.toWord > > > Nick. > > -- > You received this message because you are subscribed to the Google Groups > "MLton-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > > ------------------------------------------------------------------------------ > > _______________________________________________ > MLton-user mailing list > [email protected]; [email protected] > https://lists.sourceforge.net/lists/listinfo/mlton-user > -- You received this message because you are subscribed to the Google Groups "MLton-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. ------------------------------------------------------------------------------