[Oberon] 0X enigma

spir denis.spir at gmail.com
Tue Jun 29 14:09:29 MEST 2010


Hello,


My in-progress custom Text type had a strange behaviour in case a text is initialised with 0X (I rely on the fact that a character is automatically converted to an ARRAY OF CHAR, which is the type of the formal parameter of the method Text.init). Any other case works fine.
As a trial to elucidate the issue, I wrote the following test:

MODULE ___trial___;

IMPORT
	Out;

VAR
	chars : ARRAY 4 OF CHAR;

PROCEDURE show(chars:ARRAY OF CHAR);
BEGIN
	Out.LongInt(LEN(chars),0) ; Out.String(' : ') ;
	Out.String('|') ; Out.String(chars) ; Out.String('|') ;
	Out.Ln ;
END show;

BEGIN
	chars := 'abc' ; show(chars) ;
	show('abc') ;
	show('a') ;
	show(61X) ;
	show('') ;
	show(0X) ;
END ___trial___.
	
=== output ===
4 : |abc|
4 : |abc|
2 : |a|
2 : |a|
1 : ||
2 : ||

I thought and read that 0X is equivalent to ''. It is equivalent for output, since 0X produces none per definition; but its internal representation is not the same. This indeed fools my code (or rather my initial assumption): the init method records an actual content size of 1.
Actually, this behaviour may be better, allowing the user to define a String really containing a single char (or byte) that actually holds 0X.
But I would like to elucidate the enigma anyway.


Denis
________________________________

vit esse estrany ☣

spir.wikidot.com


More information about the Oberon mailing list