BString doesn't have lvalue operator[] anymore

I was trying to build some old BeOS code and got this error message.

According to the BeBook there were two operator

char operator**(int32 index)** const
inline char &operator**(int32 index)**

However last one has been removed from Haiku’s BString.

What was a rationale of this change? It doesn’t seem necessary, however it causes regression and confuses people using BeBook as a reference.

1 Like

It should still be available when using GCC 2.95

See the relevant commit:

1 Like

It still doesn’t explain the rationale behind it. Lack of inlining?

char& operator(int i) { return (const_cast<char *>(String())[i]); }

or implement it as a an external operator

Why break backward compatibility?

1 Like

Just follow the link to the discussion mentioned in the commit. IIRC, this allows for much cheaper reference counted copies.

BTW, Haiku aims for binary compatibility; the source compatibility is not that important.

How so if there is still String() method giving you direct access to the string buffer?

API consistency is still important, especially since all programming books are written for BeOS, not for Haiku.

1 Like

String() returns a const char* unlike , which allowed to directly alter the underlying buffer.

API consistency is indeed important, but this change does in fact improve it. Consistency does not mean the same as the Be API, and it certainly does not mean we aren’t allowed to change and improve things.

Documentation needs to be updated. And you cannot really expect to get a 25 year old book from your shelf and believe the world hasn’t changed. That is certainly not what Haiku is about, at least.

2 Likes

You are right, but unfortunately there is nothing newer to get into Haiku software development. Unless you can recommend one.

I only know of DarkWyrm’s programming lessons with Haiku. I’m not sure if that’s kept up to date, though, either.

Apart from that, you could look into the smaller apps that come with Haiku, and learn from those. At least there should be one for pretty much any topic you might be interested in.

Isn’t that a [UB]([dcl.type.cv]) and explains why it’s been removed?