• Welcome to PlanetSquires Forums.
 

Usage of Fixed Length Strings

Started by Jeff Marshall, March 10, 2024, 10:09:30 AM

Previous topic - Next topic

Jeff Marshall

Hello all.  I am a developer / maintainer on the freebasic compiler project.

I have been recently exploring freebasic's handling of all string types getting prepared to make another go at improving a number of fbc string internals and what is offered to users.

We are working on a change for STRING*N, that basically makes it compatible with QB, QB64 (and powerbasic, I think)
- occupies exactly N bytes
- no implicit null terminator
- padded with spaces on initialization and assignment
- can have embedded chr(0)'s
- for the most part is like QB's handling of STRING*N

However, this change will almost certainly break user code that employs STRING*N (which currently is equivalent to ZSTRING*(N+1) )

It seems that usage of STRING*N is rare but not never.  My presumption is that over the years ZSTRING*N has been much more favoured over STRING*N since they behave nearly identically but ZSTRING*N tends to describe the behaviour better.

I have been trying to go through some of the larger code bases looking to find where STRING*N has been used and what impact it will have on users and developers.

---
When I look at the WinFBE and WinFBX code bases I see that STRING*N has been used a few times, but overall mostly not.  In some cases ZSTRING*N is probably a good choice too.

I am trying to get a feel for motivation for programmers choosing STRING*N.

My concern is that perhaps there is a usage of STRING*N that is intentional and that I have missed the usage.  If there is, perhaps this can be addressed.


Any feed back is appreciated.

Paul Squires

Looks like Frank ran into a couple of the new SPACE issues using code from Jose's WinFBX library.
https://www.planetsquires.com/protect/forum/index.php?topic=4752.msg36080;topicseen#msg36080

I am not sure how active Jose is with programming these days so when you have finalized your new changes I can make the changes to the WinFBX code.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Hello everybody,

I am busy collaborating on an encyclopaedia of French cinema.

https://www.aidememoirecinema.fr/

I don't remember ever using AS STRING * with FreeBasic because all my WinFBX code is unicode.

Many, many years ago, when I was working with the DOS operating system, I used it to work with random files.

Jeff Marshall

Thank you for the feedback.

Quote from: José Roca on March 13, 2024, 06:28:08 AMI don't remember ever using AS STRING * with FreeBasic because all my WinFBX code is unicode.
It is indeed hardly used at all and 2 instances I seen only in comments:
./Afx/AfxWin.inc:958:
'   DIM wszInitialDir AS STRING * 260 = CURDIR

./Afx/AfxWin.inc:1061:
'   DIM wszInitialDir AS STRING * 260 = CURDIR

./Examples/Sample_Projects/DShow_PlayClip/DShow_PlayClip.bas:168:
DIM wszInitialDir AS STRING * MAX_PATH = CURDIR

./TLB_100/TLB_100.bas:135:
DIM wszInitialDir AS STRING * 260 = CURDIR

./TLB_100/TLB_100.bas:173:
DIM wszInitialDir AS STRING * 260 = CURDIR

QuoteMany, many years ago, when I was working with the DOS operating system, I used it to work with random files.
I kind of miss that feature for working with some kinds of files; one motivation of several varied motivations for working on this old, probably nobody cares about feature.

philbar

Quote from: Jeff Marshall on March 13, 2024, 08:22:34 PM
QuoteMany, many years ago, when I was working with the DOS operating system, I used it to work with random files.
I kind of miss that feature for working with some kinds of files; one motivation of several varied motivations for working on this old, probably nobody cares about feature.

I care. I work with a database consisting of gigabytes of Fortran-generated flat files with embedded b-trees. It is alive and well and being added to daily. In each record, the fields that are character type are fixed-length, space-padded strings. Byte arrays are an inconvenient substitute for a string type that exactly matches the data. I'd like to do the occasional new programs with FB, as WinFBE makes it easy to create attractive GUI interfaces.

Maybe I'm a dinosaur. Incidentally, I've been following the discussion of this on the FB forum. It sounded so easy at first...

José Roca

#5
> It is indeed hardly used at all and 2 instances I seen only in comments:

These are all unintentional errors likely caused by copying code from one part to another. It should be WSTRING * instead of STRING *

If it was still using random files, surely I would need fixed strings.

Jeff Marshall

Quote from: philbar on March 14, 2024, 03:23:16 AMIncidentally, I've been following the discussion of this on the FB forum.
ah nice!, excellent to hear.  Our goal is to keep the development discussions out in the open as much as possible and let everyone know what is going on even if at times it is full of a bunch of technical details.

> It sounded so easy at first...

I find that there are many concerns that in isolation would be easy (simple) and then when investigating how they interact with other concerns become hard (complicated).  I think 'easy' or 'hard' is convenient for generalizing and summing up but really doesn't capture the nuances of the challenge.

Jeff Marshall

Quote from: José Roca on March 14, 2024, 02:40:12 PMIt should be WSTRING * instead of STRING *
Thank-you.  Ok, I conclude that our string*n endeavour will not adversely affect WinFBE (WinFBX).