From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.9 required=3.0 tests=BAYES_00,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.6 Date: Tue, 30 Nov 2021 08:40:41 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: Re: Empty String confusion; Positive and Natural Content-Language: en-GB Newsgroups: comp.lang.ada References: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com> From: ldries46 In-Reply-To: <053c8a45-2829-4f2e-925c-b72308c1fe61n@googlegroups.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Organization: KPN B.V. Path: eternal-september.org!reader02.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.ams4!peer.am4.highwinds-media.com!news.highwinds-media.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail Injection-Date: Tue, 30 Nov 2021 08:40:44 +0100 Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com" X-Received-Bytes: 2169 Xref: reader02.eternal-september.org comp.lang.ada:63166 List-Id: Op 29-11-2021 om 18:34 schreef Kevin Chadwick: > I suspect that I am doing something outside of Ada norms. > > Are empty strings avoided in Ada? > > I have a function to create a record containing strings amongst other things like a subtyped integer, simply to group the outputs neatly of another function. > > If something goes wrong and I run the create function with "" then the strings length is zero. Why is a string type Positive and not Natural, because empty strings are in fact useless? > > I guess I shall consider re-engineering my functions, rather than add checks, but all thoughts are welcome. From your description, I suspect that you are using different declarations for the strings you use for instance while " " in fact is a string(1.1) you try to put this in a string(1 .. 5). To avoid this kind of problems I generally use the package Ada.Strings.Unbounded where have possibilities to operate strings without caring for the length. Changing between strings and unbounded strings is possible with functions in the package. I would then advice you to create an variable at a position where it is reachable from all packages where you use it: Empty_String : Unbounded_String := To_Unbounded_String("");