From: adoyle@bbn.com (Allan Doyle)
Subject: Re: C Strings in Ada?
Date: 11 Jun 90 12:57:23 GMT [thread overview]
Message-ID: <57245@bbn.BBN.COM> (raw)
In-Reply-To: 1304@software.software.org
Whew, the nesting is getting too deep. I sliced out the parts I want to
comment on...
>>What is the best way to represent C_Strings in Ada?
>$$ procedure to_c (str : string)
>$$ is
>$$ procedure c_routine (addr : system.address);
>$$ pragma interface (C, c_routine); -- (void) c_routine(s)
>$$ -- char * s;
>$$ c_string : constant string := str & Ascii.NUL;
>$$ begin
>$$ c_routine(c_string(c_string'first)'address);
>$$ end to_c;
>I dont think this solution *requires* heap allocation. A good compiler would
>be free to use stack space for the C strings in these cases, both for
>the local constant c_string and for the return value. Of course, there is
>the overhead of copying the strings but the allocation can be relatively
>cheap.
>
>-----------------------------------------------------------------------
>Alex Blakemore Internet: blakemore@software.org
>Software Productivity Consortium UUNET: ...!uunet!software!blakemore
>2214 Rock Hill Rd, Herndon VA 22070 Bellnet: (703) 742-7125
Judging from the replies about heap space, I'm getting a little worried.
Do you guys mean to tell me that it's compiler dependent how to allocate
the 'c_string' constant? This is just the sort of thing that makes me
mistrust Ada for a realtime application that has to run for a long time
without any memory leaks. If I take the worst case assumption that c_string
is being allocated from the heap and add it to the worst case assumption
that my Ada run-time will not be doing garbage collection (perfectly legal,
I understand), then how many of these little beasties can I convert from
Ada to C before I run out of memory?
Allan Doyle adoyle@bbn.com
BBN Systems and Technologies Corporation (617) 873-3398
70 Fawcett Street, Cambridge, MA 02138
next prev parent reply other threads:[~1990-06-11 12:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
1990-06-04 22:45 C Strings in Ada? Andy DeFaria
1990-06-07 17:41 ` stt
1990-06-08 16:00 ` Andy DeFaria
1990-06-10 20:38 ` Alex Blakemore
1990-06-11 12:57 ` Allan Doyle [this message]
1990-06-11 14:59 ` David Kassover
1990-06-11 19:48 ` Allan Doyle
1990-06-11 21:01 ` David Kassover
1990-06-11 22:30 ` Mike Murphy
1990-06-13 21:20 ` Edward Falis
1990-06-11 17:53 ` David Emery
1990-06-11 19:59 ` Allan Doyle
1990-06-15 7:53 ` Jeff Bartlett
1990-06-11 22:39 ` Andy DeFaria
1990-06-12 14:04 ` David Emery
1990-06-12 18:11 ` Mike Murphy
1990-06-13 13:43 ` stt
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox