[Info-vax] Any Way to Pass Arrays of Strings from C to Basic?
Arne Vajhøj
arne at vajhoej.dk
Fri Nov 8 20:26:44 EST 2019
On 11/8/2019 5:13 PM, seasoned_geek wrote:
> On Friday, November 8, 2019 at 12:36:23 PM UTC-6, Simon Clubley wrote:
>> On 2019-11-08, Arne Vajhøj <arne at vajhoej.dk> wrote:
>>> On 11/8/2019 8:16 AM, Simon Clubley wrote:
>>
>> The key word in the above is _directly_, for example, as in can you
>> directly pass a null terminated string into a DEC Basic function ?
>
> Can you do it? Yeah. Relying on a null terminated sequence of bytes
> is an architectural catastrophe that should never be allowed in any
> production system, but you could.
It may be difficult to find a production system where there is not
some code using it.
But it is not a good design.
> When one is passing around UTF-8, UTF-16, and basically anything
> other than raw 8-bit ASCII the concept of a "null terminated string"
> is a pointless one.
A C wide char string is still null terminated - just with a wchar_t
being 0 instead of a char being 0.
> That is one of the reasons the QString class in Qt doesn't let
> developers directly manipulate the raw buffer. There are other C++
> string classes designed much the same.
Really?
How does:
void f()
{
QString s = "ABC";
cout << s.toStdString() << endl;
QChar *c = s.data();
c[1] = 'X';
cout << s.toStdString() << endl;
}
work for you?
> The usefulness of a char [] is at an end. Continuing development with
> it is a catastrophe in the making. Every system you write today will
> either have to directly support one of the UTF sequences out of the
> gate or it will have to within 3 years. Even if you are on an
> operating system which doesn't support it, you are going to get
> outside feeds using one or more of those encodings.
The concept of having a char array as string type was
mostly a C thing. Other languages got real string types.
And a lot of the newer languages have Unicode/UTF-8 support.
OS support is usually less important. One can write files
with UTF-8 content fine on an OS that knows nothing about UTF-8.
Of course one cannot use UTF-8 for the filename, but often one
can live with that constraint.
Arne
More information about the Info-vax
mailing list