hsc: Passing -1 as CString/Ptr a?

Volker Stolz vs@foldr.org
Thu, 22 Nov 2001 13:57:32 +0100

Hi, I want to invoke the C-function 'dlsym', which has three 
possible options for a parameter of type (void*):

- void* to a string, i.e. CString in Haskell
- RTLD_NEXT = (void *)(-1)

The first two ones are no problem, I can use a CString and
'nullPtr'. For the last one, I have the problem that in
the "Next"-case I cannot write

pack :: Flag -> CString
pack Null = nullPtr
pack Name str = str
pack Next = #const RTLD_NEXT

because there's no way to cast Int to a Ptr -- at least I
didn't find any. Unluckily, the C-codes (void *)(-1) even
gets expanded by hsc to the literal "4294967295" which can't be
right either.

So currently I'm facing two possible solutions:
  pack Next = nullPtr `plusPtr` 4294967295 (expanded from "... #const RTLD_NEXT")
  pack Next = nullPtr `plusPtr` (-1) (which is not a good idea since it doesn't
                                       use the C-constant)

"Ptr" is abstract so I cannot create this Ptr myself. Maybe the Ptr-module
just lacks a 'minusOnePtr' similar to 'nullPtr'?
Volker Stolz * vs@foldr.org * PGP + S/MIME