comp.lang.ada
 help / color / mirror / Atom feed
* Re: Is there an end of string like in C
       [not found] <1151691630.276880.203280@75g2000cwc.googlegroups.com>
@ 2006-06-30 18:57 ` Pascal Obry
  2006-06-30 19:20 ` Martin Dowie
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Pascal Obry @ 2006-06-30 18:57 UTC (permalink / raw)
  To: Chris L

Chris L a �crit :
> 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?

Of course everybody on this list will be able to answer your question.
Yet, asking for such basic things tell us that you have probably not
read any Ada text book. The first step is to do that, then please come
back for some real Ada questions :)

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there an end of string like in C
       [not found] <1151691630.276880.203280@75g2000cwc.googlegroups.com>
  2006-06-30 18:57 ` Is there an end of string like in C Pascal Obry
@ 2006-06-30 19:20 ` Martin Dowie
  2006-06-30 19:24 ` Gautier
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: Martin Dowie @ 2006-06-30 19:20 UTC (permalink / raw)


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?

As Pascal points out, this really shows you haven't tried to answer this 
very simple question yourself. As a starter, I'll be more generous than 
Pascal and point you to http://www.adapower.com/ where you'll find some 
online books and tutorials.

As an aside ask yourself, if /you/ were designing a language from 
scratch would you include "null terminated strings"? Are they a good idea?

Cheers
-- Martin



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there an end of string like in C
       [not found] <1151691630.276880.203280@75g2000cwc.googlegroups.com>
  2006-06-30 18:57 ` Is there an end of string like in C Pascal Obry
  2006-06-30 19:20 ` Martin Dowie
@ 2006-06-30 19:24 ` Gautier
  2006-06-30 19:38 ` Björn Persson
  2006-06-30 20:12 ` Jeffrey R. Carter
  4 siblings, 0 replies; 5+ messages in thread
From: Gautier @ 2006-06-30 19:24 UTC (permalink / raw)


Chris L wrote:

> In C, there is an end of string character ('\0'). Is there one in Ada?

No, this is a C specialty - and also a typical nuisance of C...
In Ada you know the array bounds, and a string is an array of Character.

> Can you give me code that checks for it in an array?

s'Length give you the string length, without any loop, or the risk of 
a missing end-of-string character.

> Thank you,
> Christopher Lusardi

HTH, Gautier
_______________________________________________________________
Ada programming -- http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, e-mail address on the Web site!



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there an end of string like in C
       [not found] <1151691630.276880.203280@75g2000cwc.googlegroups.com>
                   ` (2 preceding siblings ...)
  2006-06-30 19:24 ` Gautier
@ 2006-06-30 19:38 ` Björn Persson
  2006-06-30 20:12 ` Jeffrey R. Carter
  4 siblings, 0 replies; 5+ messages in thread
From: Björn Persson @ 2006-06-30 19:38 UTC (permalink / raw)


Chris L wrote:
> In C, there is an end of string character ('\0'). Is there one in Ada?

Null-terminated buffers are a very very poor substitute for arrays. They 
are the cause of a majority of all the security holes in computer 
systems. Of course we don't do that in Ada. Read here:

http://en.wikibooks.org/wiki/Ada_Programming/Strings#Unbounded-length_string_handling

-- 
Bj�rn Persson                              PGP key A88682FD
                    omb jor ers @sv ge.
                    r o.b n.p son eri nu



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Is there an end of string like in C
       [not found] <1151691630.276880.203280@75g2000cwc.googlegroups.com>
                   ` (3 preceding siblings ...)
  2006-06-30 19:38 ` Björn Persson
@ 2006-06-30 20:12 ` Jeffrey R. Carter
  4 siblings, 0 replies; 5+ messages in thread
From: Jeffrey R. Carter @ 2006-06-30 20:12 UTC (permalink / raw)


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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-06-30 20:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1151691630.276880.203280@75g2000cwc.googlegroups.com>
2006-06-30 18:57 ` Is there an end of string like in C Pascal Obry
2006-06-30 19:20 ` Martin Dowie
2006-06-30 19:24 ` Gautier
2006-06-30 19:38 ` Björn Persson
2006-06-30 20:12 ` Jeffrey R. Carter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox