[m-dev.] What's the deal with integer types in Mercury's C source.

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Sep 9 16:02:08 AEST 2011




On Fri, 9 Sep 2011, Paul Bone wrote:

>
> Hi guys.
>
> In C source we often use MR_Integer and MR_Unsigned, these are guaranteed to be
> at least pointer-sized.  We also use MR_uint_least32_t and friends when we want
> something at least that particular size.
>
> I want an integer that is exactly 32 bits on 32 and 64 bit platforms.  I'm
> trying to make some inline assembler things as compatible as possible with
> different C compilers on i386 and x86_64.  The assembly code it's self is
> compatible with either i386 or x86_64 but I'd also like it's parameter to be
> exactly 32 bits to match the operand size I'm using in the assembly code.
>
> How portable is uint32_t?  Or should I use some other type to get _exactly_ a
> 32bit unsigned int?

uint32_t is C99; most C compilers provide it;  MSVC 2010 provides stdint
and hence uint32_t, older versions of MSVC do not.
For older versions of MSVC (and indeed for 2010) you could use the
unsigned __int32 type.
(http://msdn.microsoft.com/en-us/library/29dh1w7z(v=VS.100).aspx)

I suggest adding MR_uint32_t etc to runtime/mercury_types.h and defining
them appropriately.  (That at least gives us a way of dealing with older
or broken C compilers.)

Julien.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list