[Info-vax] Pascal question
Arne Vajhøj
arne at vajhoej.dk
Mon Jan 21 23:41:26 EST 2019
On 1/21/2019 10:52 PM, Dave Froble wrote:
> John, did any other languages (besides Basic) use the VMS dynamic string
> types?
>
> The implementation on Basic+ was rather interesting. If one set string
> A$ = B$, it would not copy the data, it changed the pointer for A$ to
> the same value as the pointer for B$. Things could get interesting. If
> A$ was a label in an I/O buffer, it would no longer be a label in the
> buffer.
That type of "smart" ideas are still seen.
String is immutable in Java. At least using normal methods, so in
some Java versions use of non-normal methods can give funky results.
$ type StringFun.java
public class StringFun {
public static void main(String[] args) throws Exception {
String s1 = "ABCEF";
System.out.printf("s1=%s\n", s1);
String s2 = s1.substring(1, 4);
System.out.printf("s2=%s\n", s2);
// start dirty
// note: only access s1 not s2
java.lang.reflect.Field value =
String.class.getDeclaredField("value");
value.setAccessible(true);
char[] buf = (char[])value.get(s1);
buf[2] = 'X';
// end dirty
System.out.printf("s1=%s\n", s1);
System.out.printf("s2=%s\n", s2);
}
}
$ @sys$startup:java$60_setup
$ java -version
java version "1.6.0"
Java(TM) SE Runtime Environment "1.6.0-7"
Java HotSpot(TM) 64-Bit Server VM (build 20.7-b07, mixed mode)
$ javac StringFun.java
$ java StringFun
s1=ABCEF
s2=BCE
s1=ABXEF
s2=BXE
$ @sys$startup:java$80_setup
$ javac StringFun.java
$ java StringFun
s1=ABCEF
s2=BCE
s1=ABXEF
s2=BCE
:-)
Arne
More information about the Info-vax
mailing list