[Info-vax] VMS Basic strings class D vs class S

Arne Vajhøj arne at vajhoej.dk
Wed Feb 28 09:18:54 EST 2024


On 2/25/2024 10:38 PM, Lawrence D'Oliveiro wrote:
> On Sun, 25 Feb 2024 16:33:33 -0500, Arne Vajhøj wrote:
>> If I have understood it correctly then VMS Basic strings use class D
>> descriptors.
> 
> The “VAX BASIC User Manual” mentions both dynamic and fixed-length
> strings. Chapter 13 explains that strings are fixed-length when part of
> COMMON, MAP or RECORD statements, otherwise they are dynamic. Fixed-length
> strings obviously cannot have their storage reallocated.

And I guess that sort of makes Basic need to handle it
transparently.

$ type f.for
       program f
       character*80 s
       call print_class('ABC')
       call b1('ABC')
       call print_class(s)
       call b2(s)
       write(*,*) '|'//trim(s)//'|'
       end
$ type b.bas
sub b1(string s)
     print "|" + s + "|"
end sub
!
sub b2(string s)
     s = "ABC"
end sub
$ type x.c
#include <stdio.h>

#include <descrip.h>

void print_class(struct dsc$descriptor *s)
{
     switch(s->dsc$b_class) {
         case DSC$K_CLASS_S:
             printf("Class S\n");
             break;
         case DSC$K_CLASS_VS:
             printf("Class VS\n");
             break;
         case DSC$K_CLASS_D:
             printf("Class D\n");
             break;
         default:
             printf("Unknown class\n");
             break;
     }
}
$ for f
$ bas b
$ link f + b + x
$ run f
Class S
|ABC|
Class S
|ABC|

has to work, because of:

$ type f.bas
program f
     map (blk1) string s1 = 3
     map (blk2) string s2 = 80
     external sub b1(string)
     external sub b2(string)
     external sub print_class(string)
     external string function trim(string)
     s1 = "ABC"
     call print_class(s1)
     call b1(s1)
     call print_class(s2)
     call b2(s2)
     print "|" + trim(s2) + "|"
end
!
function string trim(string s)
     declare integer ix
     ix = len(s)
     while ix > 1 and mid$(s, ix, 1) = " "
         ix = ix - 1
     next
     trim = mid$(s, 1, ix)
end function
$ type b.bas
sub b1(string s)
     print "|" + s + "|"
end sub
!
sub b2(string s)
     s = "ABC"
end sub
$ type x.c
#include <stdio.h>

#include <descrip.h>

void print_class(struct dsc$descriptor *s)
{
     switch(s->dsc$b_class) {
         case DSC$K_CLASS_S:
             printf("Class S\n");
             break;
         case DSC$K_CLASS_VS:
             printf("Class VS\n");
             break;
         case DSC$K_CLASS_D:
             printf("Class D\n");
             break;
         default:
             printf("Unknown class\n");
             break;
     }
}
$ bas f
$ bas b
$ link f + b + x
$ run f
Class S
|ABC|
Class S
|ABC|

Arne







More information about the Info-vax mailing list