From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38c827f7e800d317 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-07-03 17:21:26 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!news-in-sterling.nuthinbutnews.com!cyclone1.gnilink.net!wn12feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail From: Dave Thompson Newsgroups: comp.lang.ada Subject: Re: conversion Message-ID: <9c25gvg8gg1p9205l6ddeu2qoj3s8ajns0@4ax.com> References: X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Date: Fri, 04 Jul 2003 00:21:26 GMT NNTP-Posting-Host: 12.89.137.26 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1057278086 12.89.137.26 (Fri, 04 Jul 2003 00:21:26 GMT) NNTP-Posting-Date: Fri, 04 Jul 2003 00:21:26 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.ada:40035 Date: 2003-07-04T00:21:26+00:00 List-Id: On Fri, 27 Jun 2003 15:26:36 +0100, Bill Findlay wrote: > On 27/6/03 13:37, in article uznk3u258.fsf@nasa.gov, "Stephen Leake" > wrote: > > > "Andrew" 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