<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></style>
</head>
<body class='hmmessage'>
> > add CARDINAL and LONGCARD as synonyms for ptrdiff_t and INT64<BR><BR>
<BR>
As I see things, there are two approximations, and nothing "exact".<BR>
INTEGER is exactly ptrdiff_t.<BR>
LONGINT is exactly long long or __int64.<BR>
<BR>
<BR>
CARDINAL is approx INTEGER (ptrdiff_t) and approx size_t, but neither is quite right.<BR>
LONGCARD is approx LONGINT (long long/__int64) and approx unsigned long long/__int64, but neither is quite right.<BR>
The C unsigned types are "full range", but the Modula-3 unsigned types are "half range".<BR>
<BR>
<BR>
Another approximation would be:<BR>
<BR>
<BR>
typedef struct {<BR>
unsigned long or something value: 31 or 63;<BR>
} CARDINAL;<BR>
<BR>
typedef struct {<BR>
unsigned long long value: 63;<BR>
} LONGCARD;<BR>
<BR>
That is at least a way to get the correct positive "half range".<BR>
but that's just worth wondering about -- passing small structs by value.<BR>
There's probably no portable way to get a >32bit bit field on a 32bit system,<BR>
even if there is "long long".<BR>
<BR>
I view this kind of a stylistic thing, kind of a correctness thing.<BR>
<BR>
If I have:<BR>
<* EXTERNAL Interface__Foo*> PROCEDURE Foo(a: CARDINAL);<BR>
<BR>
What should I write in C?<BR>
<BR>
void Foo(size_t a) { }<BR>
void Foo(ptrdiff_t a) { }<BR>
<BR>
void Foo(CARDINAL a) { } This at least looks nice, but how does one make it correct?<BR>
<BR>
Perhaps such a declaration just should not be written? Instead use INTEGER?<BR>
<BR>
Imagine our C/Modula-3 interop story were so advanced, that we generated C header files<BR>
from Modula-3 .i3 files. What then?<BR>
<BR>
<BR>
Again, I'm willing to consider the option is "don't do that".<BR>
Such an advanced system might just omit functions taking CARDINAL/LONGCARD.<BR>
After all -- where does the subrange check occur? If it is at the call, then<BR>
C code would too easily violate the safety.<BR>
If it is at the receipt, then the pattern I have too easily violates the safety<BR>
receiving the values in C.<BR>
<BR>
<BR>
Again I'm open to the idea that CARDINAL/LONGCARD don't interoperate with C.<BR>
<BR>
<BR>
- Jay<BR> <BR>> From: hosking@cs.purdue.edu<BR>> Date: Fri, 9 Apr 2010 13:00:40 -0400<BR>> To: jkrell@elego.de<BR>> CC: m3commit@elegosoft.com<BR>> Subject: Re: [M3commit] CVS Update: cm3<BR>> <BR>> I'm not sure you want always to assume that. I find these synonyms a little misleading.<BR>> <BR>> On 9 Apr 2010, at 11:35, Jay Krell wrote:<BR>> <BR>> > CVSROOT: /usr/cvs<BR>> > Changes by: jkrell@birch. 10/04/09 11:35:54<BR>> > <BR>> > Modified files:<BR>> > cm3/m3-libs/m3core/src/: m3core.h <BR>> > <BR>> > Log message:<BR>> > add CARDINAL and LONGCARD as synonyms for ptrdiff_t and INT64<BR>> <BR> </body>
</html>