Post by August KarlstromPost by Christian LuginbühlThe terminator is _not_ part of the string.
It depends on how the concept "string" is defined. In general terms, a
string is a sequence of symbols from a predetermined alphabet. If A is the
set of ASCII characters we can define this alphabet as A or as A\{null}.
Indeed. In Oberon-07 the character set is defined to be the Latin-1 set
which *does* contain the null character. Consequently, from an entirely
logical, as opposed to intuitive, point of view, it could be argued that the
null terminator should be included when counting the number of characters in
a string. Just because everybody else does it differently does not mean that
they are right ;-)
Post by August KarlstromPost by Christian LuginbühlMy Oberon is a little rusty, how do you determine the length of a string
at runtime,
To determine the length of a string stored in a character array s we do
len := 0;
WHILE s[len] # 0X DO INC(len) END;
Note that the above would give a length which is one less than the length as
defined in the Oberon-07 report. If you include the null terminator in the
count a suitable Length function would be:
PROCEDURE Length(CONST s: ARRAY OF CHAR): INTEGER;
VAR
i: INTEGER;
BEGIN
i := 0;
WHILE s[i] # 0X DO INC(i) END;
RETURN i+1
END Length;
Post by August KarlstromWe could also use a library function such as Strings.Length. Note also
that there is no way (programmatically) to determine the length of a
string constant.
I assume by this that you mean
a) there is no intrinsic (e.g. STRLEN) function and
b) you need to assign the string to an array before you can count the
characters
which is fair enough. However, using the above function it is possible to
write:
len := Length('ABC');
I inspected the ARM code generated by the Oberon-07 compiler and there is no
string copying involved - just address passing. To your mind does this count
as a programmatic way to determine the length of a string constant?
Post by August KarlstromOberon, pre Oberon rev. 27.7.2008, has the usual definition of string
length - the number of characters before the null character.
Well, not exactly ...
The earliest publicly available Oberon-07 Report that I have (Revision
1.12.2007) says:
"Every string is terminated by a (invisible) null character. The number of
characters (including the null character) in a string is called the length
of the string."
Neither the earlier Oberon (1990) nor Oberon-2 (1995) reports mention a null
character in the definition of string. The null character is only introduced
as a consequence of the process of assigning a string to an array of
characters.
Getting back to your question at the beginning of this whole discussion -
what has changed is that Oberon-07 Report Revision 1.12.2007 used to say:
9.1.3. Strings can be assigned to any array of characters, provided
the length of the string is not greater than that of the array.
whereas in the latest Revision 27.7.2008 (and some intermediate revisions)
it now says:
9.1.3. Strings can be assigned to any array of characters, provided
the length of the string is less than that of the array.
You may be interested to know that the implementation of Oberon-07 that I am
using does accept the following:
VAR
s: ARRAY 4 OF CHAR;
...
s := 'ABC';
However, it would not be reasonable to conclude from this simple experiment
that all conceivable possibilities might be correspondingly acceptable in
all implementations, either now or in the future. Having said that, I have
yet been unable to think of any technical reason why a potential Oberon-07
implementation might require the character array length (i.e. the number of
its elements) to be greater than the string length (including the null
character).
--
Chris Burrows
Armaide: Oberon-07 ARM Development System for Windows
http://www.armaide.com