Re: Is there an end of string like in C
- From: "Jeffrey R. Carter" <spam.not.jrcarter@xxxxxxxxxxxxxxxx>
- Date: Fri, 30 Jun 2006 20:12:20 GMT
Chris L wrote:
In C, there is an end of string character ('\0'). Is there one in Ada?
Can you give me code that checks for it in an array?
In Ada, a string type is a one-dimensional array type with components of a character type. You can define your own character types and your own string types. If you want to define your own end-of-string character and a library of operations that know about that character you certainly can.
The predefined type Character is a character type. The predefined type String is a string type. Its definition is
type String is array (Positive range <>) of Character;
pragma Pack (String);
The definitions of Character and String do not define an end-of-String Character or any operations that treat a Character as such.
The C approach is referred to in Ada as a bounded string; the logical value can vary in length from zero to some maximum number of characters. You can also consider an unbounded string, in which there is no upper limit to the length (except as imposed by available storage). You might want to look at Ada.Strings.Bounded and Ada.Strings.Unbounded for the Ada Way to do this sort of thing.
One advantage of the Ada Way is that all characters can be elements of a string.
This is all pretty basic and should be covered by any text or tutorial, which you should have worked through before asking questions such as this. You can find on-line texts and tutorials at www.adapower.com and www.adaworld.com.
--
Jeff Carter
"The time has come to act, and act fast. I'm leaving."
Blazing Saddles
36
.
- References:
- Is there an end of string like in C
- From: Chris L
- Is there an end of string like in C
- Prev by Date: Re: Ada in Debian: most libraries will switch to the pure GPL in Etch
- Next by Date: Re: Ada2005 Compiler
- Previous by thread: Re: Is there an end of string like in C
- Index(es):
Relevant Pages
|