comp.lang.ada
 help / color / mirror / Atom feed
From: emery@mitre-bedford.arpa  (David Emery)
Subject: Re: question on constant arrays
Date: 5 Feb 93 01:58:55 GMT	[thread overview]
Message-ID: <EMERY.93Feb4205855@dr_no.mitre.org> (raw)

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?

             reply	other threads:[~1993-02-05  1:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-02-05  1:58 David Emery [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-02-05 14:10 question on constant arrays Mike Lijewski
1993-02-04  4:48 agate!spool.mu.edu!olivea!charnel!rat!koko.csustan.edu!nic.csu.net!vmsa.i
replies disabled

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