:: [DNG] Ada strings
Forside
Slet denne besked
Besvar denne besked
Skribent: kc-devuan
Dato:  
Til: dng
Emne: [DNG] Ada strings
7 Oct 2024 00:49:50 Steve Litt <slitt@???>:

> I've studied Ada the past couple days, and I gotta tell you, Ada
> strings are very murky. From what I've learned, Ada has three kinds of
> strings:


Yes strings beyond the main fixed string in Ada take more time than they should to grok and are often complained  about.

>
> Fixed strings
> Bounded strings
> Unbounded strings
>
> Fixed strings are pretty simple but you can't reassign a different
> string to a fixed string unless the new string has identical length.
>


True. Did you find the Ada.Fixed_Strings package? The trick is to pad with spaces and you can of course replace characters as a String is an array.


> Unbounded strings require lots of conversions to use, and they're
> pretty hairy.
>


Unlike most languages Ada supports working with utf-8, utf-16 and utf-32 etc. rather than working in utf-8 or bytes (go) or utf-16 (java, dart) and converting to others.

You might be interested in this
https://blog.adacore.com/introduction-to-vss-library


> My investigation of bounded strings tells me that every single guidance
> and example of bounded strings on the Internet is wrong.
>


Bounded is arguably pointless as you can do the same with a String declared as a package global.


> So far I've found dealing with strings in Ada to be nasty.
>


The basic string is far nicer than Cs null terminated char array. In what way?

> I'm using gnatmake 13.2.0 . I have no idea if it's Ada 2005, 2012, or
> 2022. I'm guessing that different versions break things from other
> versions.


Not really, Ada is very stable and I'm not sure but it may play into part of the String complexity. You can choose Ada 83, 95, 2005, 2012 or 2022. The default still isn't the 2022 ISO so unless you specify 2022 as a gnat flag (I do) then it will be 2012. Grady Booch 83 components still compile alongside Ada 2022 just fine. However the Ada 95 versions of them won't work in 83 mode or even with a light runtime as they require protected object support. As I use a light runtime for embedded I kind of wish protected object support and safe tasking features hadn't been added with Ada 95 but on Linux or a full runtime then they are great.