<br><br><div class="gmail_quote">On Thu, Feb 26, 2009 at 11:55 AM, Jonathan S. Shapiro <span dir="ltr"><<a href="mailto:shap@eros-os.com">shap@eros-os.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
I have started trying to encode the interfaces of various libraries<br>
that are written in C, and I have hit a snag. The definition of C does<br>
not specify the size of short, int, long, and as a practical matter<br>
most libraries have used these "loose" definitions. This raises a<br>
problem of compatibility. On any given platform, there is a type in<br>
BitC that maps to "int" in that platform, but there is no type in BitC<br>
that maps to "int" generally.<br>
<br>
In abstract, there seem to be two ways to handle this:<br>
<br>
1. Have a module that defines *aliases* for c_int, c_long, c_short, etc.<br>
2. Introduce c_int and friends as first-class integer types that are<br>
*distinct from* the BitC types, but also define conversion functions<br>
and arithmetic operations over these types.<br>
<br>
The main disadvantage to [1] is that certain classes of portability<br>
error are not caught at compile time. If "word" is an alias, then an<br>
add of the form:<br>
<br>
(+ x:int32 y:word)<br>
<br>
will compile on a 32-bit platform but not on a 64-bit platform. If<br>
"word" is a type in its own right, the compiler will complain about<br>
this usage. This is why we made word a distinct type for vector sizes.<br>
<br>
Introducing typealias raises some challenges related to name spaces.<br>
These challenges are surmountable, but I'm really trying not to make<br>
major language changes at this point. Adding new types for things like<br>
c_int is very easy.<br>
<br>
I would appreciate thoughts and reactions on this issue of<br>
C-compatible integer types.<br></blockquote><div><br>Usually is enough to have a native size integer type that works with 32 bits integers and do<br>implicit widening of them on 64 bits archs. This is safe since BitC doesn't support 16bits targets.<br>
<br>Most 64bits targets handle mixed 32-64 bits math just fine.<br><br><br><br></div></div>