6.1.0980 COUNT CORE

( c-addr1 -- c-addr2 u )

Return the character string specification for the counted string stored at c-addr1. c-addr2 is the address of the first character after c-addr1. u is the contents of the character at c-addr1, which is the length in characters of the string at c-addr2.

Testing:

T{ GT1STRING COUNT -> GT1STRING CHAR+ 3 }T

ContributeContributions

PaulHorthavatar of PaulHorth [181] Is a counted string limited to 255 chars?Request for clarification2021-03-10 14:50:29

From the description "u is the contents of the character at c-addr1" it seems to imply that the length is the size of one character and hence limited to 255. If a FORTH implementation had a cell before the characters of the string and hence a theoretical string size of max-int, would that still be a standard system?

AntonErtlavatar of AntonErtl

Yes, in a standard program a counted string can be at most 255 chars long. On a system with a larger char size (e.g., on a word-addressed machine) the count (and therefore counted strings) can be larger, but a standard program cannot rely on that.

A Forth system with a COUNT equivalent to the following

: count dup cell+ swap @ ;

would be non-standard unless 1 cells gives 1 on this system.

I recommend using the c-addr u representation (where only the addressable and available memory limits string length) instead of counted strings. I don't use counted strings.

Closed

PaulHorthavatar of PaulHorth

So just to confirm my understanding, there is nothing non-standard if using, say, PARSE and having c-addr u with u > 255 ?

Open

AntonErtlavatar of AntonErtl

For the c-addr u representation, u can be >255 (basically any value). Concerning PARSE, a standard program cannot use lines >128 chars in files, >80 chars on the command line, but blocks have 1024 chars, and there are no limits for EVALUATEd strings, so yes, there can be PARSEd strings with >255 chars.

AntonErtlavatar of AntonErtl

The question has been answered. Closing.

Closed
Reply New Version

oakavatar of oak [431] "character string specification"Request for clarification2026-06-14 22:39:57

What does "character string specification" mean? I did a search and this term appears only here.

I also couldn't find terminology in the specification that describes a counted string on the stack (i.e. "c-addr u"), which differs from a counted string at a memory address (i.e. a char length followed by character data).

If "character string specification" were defined to mean "c-addr u" on the stack, that could be helpful, as it seems to be described in varying ways across the spec. For example, TYPE says "the character string specified by c-addr and u", while S" says "c-addr and u describing a string". But perhaps a better, clearer term could be coined. The definition of "counted string" could also be extended to mention that when used as "counted string on the stack" means "c-addr u".

For now, it might be clearer here to change the description of this word to, say,

Return the character string described by c-addr2 and u for the counted string stored at c-addr1. c-addr2 is the address of the first character after c-addr1. u is the contents of the character at c-addr1, which is the length in characters of the string at c-addr2.

This is my first time commenting on this document. Please let me know if I misstepped anywhere. :)

AntonErtlavatar of AntonErtl

In 2.1 the memory respresentation without a count byte gets the term "character string" (or "string"), and the memory representation with a count byte gets the term "counted string".

3.1.3.4 describes the on-stack representation of a counted string (the address of the count byte). 3.1.4.2 describes the on-stack representation of a character string (c-addr u).

Looking at various words, such as SEARCH, SLITERAL and /STRING, the standard seems to use either "string" or "character string" for strings described with c-addr u, consistent with 2.1.

So I agree that your suggestion is an improvement over the current wording.

Reply New Version