Sujet : Re: basic BASIC question
De : arne (at) *nospam* vajhoej.dk (Arne Vajhøj)
Groupes : comp.os.vmsDate : 01. Feb 2025, 02:39:22
Autres entêtes
Organisation : SunSITE.dk - Supporting Open source
Message-ID : <679d7b49$0$713$14726298@news.sunsite.dk>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
On 1/31/2025 8:38 PM, Arne Vajhøj wrote:
On 1/31/2025 5:05 PM, Dan Cross wrote:
In article <679d26bd$0$713$14726298@news.sunsite.dk>,
Arne Vajhøj <arne@vajhoej.dk> wrote:
But there is no consistency between languages.
>
$ type dump.for
[snip]
>
I don't know why this should be surprising?
I don't know if it is surprising, but it is inconsistent.
Fortran Pascal C Basic
true literal -1 1 usually 1 usually -1
false literal 0 0 0 0
test low bit set low bit set not 0 not 0
4 languages - 4 ways of doing it.
Regarding the test:
$ type m.pas
program m(input,output);
type
ia5 = array [1..5] of integer;
[external]
procedure b(%ref v : ia5); external;
var
v : ia5;
begin
v[1] := -2;
v[2] := -1;
v[3] := 0;
v[4] := 1;
v[5] := 2;
b(v);
end.
$ type b.bas
sub b(integer v() by ref)
external string function s(integer)
external sub f(integer dim() by ref)
print using "Basic : 'E 'E 'E 'E 'E", s(v(0)), s(v(1)), s(v(2)), s(v(3)), s(v(4))
call f(v())
end sub
!
function string s(integer v1)
if v1 then
s = "TRUE "
else
s = "FALSE"
end if
end function
$ type f.for
subroutine f(v)
logical*4 v(5)
write(*,'(1x,a,5(l,4x))') 'Fortran :',v(1),v(2),v(3),v(4),v(5)
call c(v)
end
$ type c.c
#include <stdio.h>
void p(int *v);
void c(int *v)
{
printf("C :");
for(int i = 0; i < 5; i++) {
if(v[i]) {
printf(" TRUE ");
} else {
printf(" FALSE");
}
}
printf("\n");
p(v);
}
$ type p.pas
module p(input, output);
type
ia5 = array [1..5] of boolean;
[global]
procedure p(v : ia5);
begin
writeln('Pascal : ', v[1]:1, ' ', v[2]:1, ' ', v[3]:1, ' ', v[4]:1, ' ', v[5]:1);
end;
end.
$ pas m
$ bas b
$ for f
$ cc c
$ pas p
$ link m + b + f + c + p
$ run m
Basic : TRUE TRUE FALSE TRUE TRUE
Fortran : F T F T F
C : TRUE TRUE FALSE TRUE TRUE
Pascal : F T F T F
Arne