comp.lang.ada
 help / color / mirror / Atom feed
From: Dave Thompson <david.thompson1@worldnet.att.net>
Subject: Re: conversion
Date: Fri, 04 Jul 2003 00:21:26 GMT
Date: 2003-07-04T00:21:26+00:00	[thread overview]
Message-ID: <9c25gvg8gg1p9205l6ddeu2qoj3s8ajns0@4ax.com> (raw)
In-Reply-To: BB2212AC.3878%yaldnifw@blueyonder.co.uk

On Fri, 27 Jun 2003 15:26:36 +0100, Bill Findlay
<yaldnifw@blueyonder.co.uk> wrote:

> On 27/6/03 13:37, in article uznk3u258.fsf@nasa.gov, "Stephen Leake"
> <Stephe.Leake@nasa.gov> wrote:
> 
> > "Andrew" <andrew@carroll-tech.net> writes:
> >> A fixed string in Ada (to me) is like declaring a char [], you must
> >> specify a size at compile time.
> > 

I would say C char[] is kind of in-between Ada (fixed) String 
and Bounded_String.  Yes the space allocated is fixed, 
at compile time or at best at "elaboration" time (below),
but a string value within it is by convention null-terminated 
and (thus) variable up to the allocated size minus one.

> > Yes.
> 
> Actually, no.
> The size of a fixed string is determined when its declaration is elaborated.
> 
> You specify the index subtype bounds (and hence the size) at run time.
> The bound values need not be known at compile time, although they may be.
> 
C99 does allow array size of locals to be determined at runtime; 
they are called Variable Length Arrays.
You cannot choose lowerbound, as you cannot for any 
array in C, although for strings that is rarely a big issue.
You still aren't guaranteed, and rarely if ever get, 
bounds checking, or even stack overflow checking.
And C99 isn't widely implemented yet, although this 
particular feature is already available in gcc and has 
been for some years as an extension.

It's not clear if this will be picked up by C++, especially since 
as noted elsethread they already have std::string.

> I'm not being pedantic, this is a surprise to many C* programmers.
> 
> In the case of a local string variable, it may take a different size each
> time its scope is entered, e.g.:
> 
>  function f (n : positive) return String is
>     s : String(1..n) := (others => ' ');
>  begin
>     if n > 1 then return s & f(n-1); end if;
>     return s;
>  end f;
> 
> This returns a blank string of length n(n+1)/2.

But in C you (still) can't return, or assign or pass as (value) 
argument, _any_ array, string or otherwise; trying to do so 
at most sets a pointer; and returning a pointer to local space, 
which becomes invalid on the return, is a dangerous error -- 
which some C compilers will even diagnose!

- David.Thompson1 at worldnet.att.net



  parent reply	other threads:[~2003-07-04  0:21 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-27 10:51 conversion Andrew
2003-06-27 12:22 ` conversion Dmitry A. Kazakov
2003-06-27 12:37 ` conversion Stephen Leake
2003-06-27 14:26   ` conversion Bill Findlay
2003-06-27 17:04     ` conversion Georg Bauhaus
2003-07-04  0:21     ` Dave Thompson [this message]
2003-06-27 13:25 ` conversion Robert I. Eachus
2003-06-27 18:42   ` conversion tmoran
2003-06-27 14:49 ` conversion Matthew Heaney
2003-06-27 17:10 ` conversion Georg Bauhaus
2003-06-27 17:13 ` conversion Alexander Kopilovitch
2003-06-27 17:34   ` conversion Preben Randhol
2003-06-27 22:10     ` conversion Alexander Kopilovitch
2003-06-28  9:46       ` conversion Preben Randhol
2003-06-27 22:13   ` conversion Robert I. Eachus
2003-06-30  8:52     ` conversion Dmitry A. Kazakov
2003-07-03  7:03       ` conversion Robert I. Eachus
2003-07-09  7:42         ` conversion Dmitry A. Kazakov
2003-07-09 17:04           ` conversion Robert I. Eachus
2003-07-10 10:19             ` conversion Dmitry A. Kazakov
2003-07-11  1:56               ` conversion Alexander Kopilovitch
2003-07-05  2:40     ` conversion Alexander Kopilovitch
2003-07-05  6:33       ` conversion Georg Bauhaus
2003-07-05 17:06         ` conversion Alexander Kopilovitch
2003-07-06  3:53           ` conversion Robert I. Eachus
2003-07-06  5:13             ` conversion Jeffrey Carter
2003-07-06 12:45               ` conversion Chad R. Meiners
2003-07-07  1:09             ` conversion Alexander Kopilovitch
2003-07-06 20:04           ` conversion Georg Bauhaus
2003-07-07 14:55             ` conversion Stephen Leake
2003-07-07 21:36               ` conversion Alexander Kopilovitch
     [not found] <002701c33e22$8e9deaf0$0201a8c0@win>
2003-06-29 20:15 ` conversion David C. Hoos, Sr.
  -- strict thread matches above, loose matches on Subject: below --
2003-06-29  9:41 conversion Andrew
2003-07-04 10:42 ` conversion Janeit
2003-06-28  8:46 conversion Andrew
2003-06-28  9:49 ` conversion Preben Randhol
2003-06-30 14:08 ` conversion Stephen Leake
2003-06-27 17:37 conversion Andrew
2003-06-27 17:32 ` conversion Stephen Leake
2003-06-28  2:55 ` conversion Jeffrey Carter
1998-07-22  0:00 conversion Rick
1998-07-22  0:00 ` conversion Corey Ashford
1998-07-22  0:00   ` conversion Corey Ashford
1998-07-22  0:00 ` conversion Richard Toy
replies disabled

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