 
 -- | Map arbitrary 'Enum' value to 'Tag'
 toTag :: Enum a => a -> Tag
-toTag x = MkTag { tagVal = fromEnum x }
+toTag x = MkTag { tagVal = cIntConv (fromEnum x) }
 
 -- | Map 'Tag' to arbitrary 'Enum'
 fromTag :: Enum a => Tag -> a
-fromTag = toEnum . tagVal
-
-foreign import ccall unsafe "&mpi_any_tag" anyTag_ :: Ptr Int
+fromTag = toEnum . cIntConv . tagVal
+
+foreign import ccall unsafe "&mpi_any_tag" anyTag_ :: Ptr CInt
 
 -- | Predefined tag value that allows reception of the messages with
 --   arbitrary tag values. Corresponds to @MPI_ANY_TAG@.

    | x < 0             = error "Negative Rank value"
    | otherwise         = MkRank (fromIntegral x)

foreign import ccall "&mpi_any_source" anySource_ :: Ptr Int
foreign import ccall "&mpi_root" theRoot_ :: Ptr Int
foreign import ccall "&mpi_proc_null" procNull_ :: Ptr Int
foreign import ccall "&mpi_request_null" requestNull_ :: Ptr MPIRequest
foreign import ccall "&mpi_comm_null" commNull_ :: Ptr MPIComm


{-| Haskell datatype that represents values which could be used as
tags for point-to-point transfers.
-}
newtype Tag = MkTag { tagVal :: CInt -- ^ Extract numeric value of the Tag
                    }
   deriving (Eq, Ord, Enum, Integral, Real)

