From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 5 Feb 93 14:10:54 GMT From: theory.TC.Cornell.EDU!lijewski@tcgould.tn.cornell.edu (Mike Lijewski) Subject: Re: question on constant arrays Message-ID: <1993Feb5.141054.29026@tc.cornell.edu> List-Id: In article emery@dr_no.mitre.org (David Em ery) writes: >The exact Ada analog to the C record is as follows: > type strptr is access string; > type mytype is record > name : strptr; > T : integer; > end record; > > type foo_array is array (natural range <>) of strptr; > foo : foo_array(1..2) := (new string'("Hi"), 1), > new string'("There"),2)); > >In the C example, the compiler statically allocates space for the two >string literals, and returns their address. In the Ada case, you have >to explictly allocate storage for the two strings, and use the >access value. > >Remember that in C, all strings are passed by the address of their >first element. This is not the way that Ada handles strings. > > dave >p.s. I suspect that you'll be in deep trouble with your C array of >struct if you try to use any of the standard C techniques to iterate >over the characters in the Name field. Does C guarantee that string >literals like "Hi" are null terminated? C does guarantee that string literals are null terminated. The one "oddity" allowed by ANSI C is where one initializes a fixed size character array, which is just large enough to hold the characters in the string literal excluding the null, with a literal string. That is, char word[2] = "Hi"; /* word is not null terminated */ as contrasted to letting the compiler figure out the size of the array: char word[] = "Hi"; /* word is null terminated */ Why ANSI allowed this I don't know. C++ disallows this special case. -- Mike Lijewski (H)301-982-5461 (W) 301-286-6115 Goddard Space Flight Center ARPA: lijewski@rosserv.gsfc.nasa.gov SMAIL: 446 Ridge Rd. Apt. 3, Greenbelt, MD 20770