Pages: 1
|
 |
|
Author
|
Topic: zero-length string? (Read 2338 times)
|
|
|
Charles Childers
Administrator
Sr. Member
    
Karma: +2/-0
Offline
Posts: 745
|
Thanks for bringing this up. RetroForth doesn't actually support zero-length strings (mainly because there is no use for them), but this may still be something I need to work on. I can do (and am testing) a patch that ensures that " " will return a string length of one byte, but I don't know if this is actually needed.
Does anyone have an actual use for zero-length strings? And if so, what is it?
|
|
|
|
|
Logged
|
|
|
|
|
|
anub
Newbie

Karma: +1/-0
Offline
Posts: 4
|
I believe there are uses for zero-length strings: It is the zero of string concatenation ( a+"" = ""+a = a ). It denotes a value that has no characters. (such as: a user is asked to enter an optional piece of data, and enters nothing. during processing, we look at that, get "length=0" and react accordingly)
it can be denoted by either a single zero instead of data pointer, or by a pair 0, 0. (0 for length and 0 for address, since we don't need an address)
In any case, the interpreter should react more gracefully and deterministically to such input. imnsho.
|
|
|
|
|
Logged
|
|
|
|
|
|
Charles Childers
Administrator
Sr. Member
    
Karma: +2/-0
Offline
Posts: 745
|
Ok, I came up with a fix I can tolerate in the core. Zero-length strings can now be created without causing a segfault.
|
|
|
|
|
Logged
|
|
|
|
Pages: 1
|
|
|
|
|