<html><head><base href="x-msg://217/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Surely it is just as correct to write in C:<div><br></div><div>void foo (long cardinal);</div><div><br></div><div>A Modula-3 CARDINAL is assignable to a C long without any violation.</div><div><br></div><div>Of course, the C code loses the knowledge that the value "cardinal" is actually non-negative.</div><div>You'd need "assert(cardinal > 0)" in C to manually range-check on entry to foo.</div><div><br></div><div>Similarly, for Modula-3</div><div><br></div><div>foo(): CARDINAL</div><div><br></div><div>you'd need C:</div><div><br></div><div>long foo() {</div><div> long result;</div><div> ...</div><div> assert(result > 0);</div><div> return result;</div><div>}</div><div><br></div><div><div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; -webkit-text-decorations-in-effect: none; text-indent: 0px; -webkit-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div><font class="Apple-style-span" color="#0000FF"><font class="Apple-style-span" face="Gill Sans"><span class="Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans'; "><span class="Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans'; ">Antony Hosking</span></span></font></font><font class="Apple-style-span" face="Gill Sans"><span class="Apple-style-span" style="font-family: 'Gill Sans'; "><span class="Apple-style-span" style="font-family: 'Gill Sans'; "><span class="Apple-converted-space"> </span>|<span class="Apple-converted-space"> </span></span></span><span class="Apple-style-span" style="font-family: 'Gill Sans'; "><span class="Apple-style-span" style="font-family: 'Gill Sans'; ">Associate Professor</span></span><span class="Apple-style-span" style="font-family: 'Gill Sans'; "><span class="Apple-style-span" style="font-family: 'Gill Sans'; "> | Computer Science | Purdue University</span></span></font></div><div><font class="Apple-style-span" face="GillSans-Light"><span class="Apple-style-span" style="font-family: GillSans-Light; ">305 N. University Street | West Lafayette | IN 47907 | USA</span></font></div><div><font class="Apple-style-span" color="#0000FF" face="Gill Sans"><span class="Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans'; "><span class="Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans'; ">Office</span></span></font><font class="Apple-style-span" face="GillSans-Light"><span class="Apple-style-span" style="font-family: GillSans-Light; "><span class="Apple-style-span" style="font-family: GillSans-Light; "> +1 765 494 6001 |<span class="Apple-converted-space"> </span></span></span></font><font class="Apple-style-span" color="#0000FF" face="Gill Sans"><span class="Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans'; "><span class="Apple-style-span" style="color: rgb(0, 0, 255); font-family: 'Gill Sans'; ">Mobile</span></span></font><font class="Apple-style-span" face="GillSans-Light"><span class="Apple-style-span" style="font-family: GillSans-Light; "><span class="Apple-style-span" style="font-family: GillSans-Light; "><span class="Apple-converted-space"> </span>+1 765 427 5484</span></span></font></div><div><font class="Apple-style-span" face="GillSans-Light"><br class="khtml-block-placeholder"></font></div></span></span></span></span></span></span></span><br class="Apple-interchange-newline"></span></div></span></span><br class="Apple-interchange-newline">
</div>
<br><div><div>On 10 Apr 2010, at 08:07, Jay K wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div class="hmmessage" style="font-size: 10pt; font-family: Verdana; ">> > 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:<span class="Apple-converted-space"> </span><a href="mailto:hosking@cs.purdue.edu">hosking@cs.purdue.edu</a><br>> Date: Fri, 9 Apr 2010 13:00:40 -0400<br>> To:<span class="Apple-converted-space"> </span><a href="mailto:jkrell@elego.de">jkrell@elego.de</a><br>> CC:<span class="Apple-converted-space"> </span><a href="mailto:m3commit@elegosoft.com">m3commit@elegosoft.com</a><br>> Subject: Re: [M3commit] CVS Update: cm3<br>><span class="Apple-converted-space"> </span><br>> I'm not sure you want always to assume that. I find these synonyms a little misleading.<br>><span class="Apple-converted-space"> </span><br>> On 9 Apr 2010, at 11:35, Jay Krell wrote:<br>><span class="Apple-converted-space"> </span><br>> > CVSROOT: /usr/cvs<br>> > Changes by: jkrell@birch. 10/04/09 11:35:54<br>> ><span class="Apple-converted-space"> </span><br>> > Modified files:<br>> > cm3/m3-libs/m3core/src/: m3core.h<span class="Apple-converted-space"> </span><br>> ><span class="Apple-converted-space"> </span><br>> > Log message:<br>> > add CARDINAL and LONGCARD as synonyms for ptrdiff_t and INT64<br>><span class="Apple-converted-space"> </span><br></div></span></blockquote></div><br></div></div></body></html>