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=2.1 required=5.0 tests=BAYES_05,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!attcan!uunet!samsung!usc!snorkelwacker!mit-eddie!bbn.com!adoyle From: adoyle@bbn.com (Allan Doyle) Newsgroups: comp.lang.ada Subject: Re: C Strings in Ada? Message-ID: <57245@bbn.BBN.COM> Date: 11 Jun 90 12:57:23 GMT References: <920024@hpclapd.HP.COM> <920025@hpclapd.HP.COM> <1304@software.software.org> Sender: news@bbn.com Reply-To: adoyle@vax.bbn.com (Allan Doyle) Organization: Bolt Beranek and Newman Inc., Cambridge MA List-Id: 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