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