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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,404527a85668e8ac X-Google-Attributes: gid103376,public From: Al Johnston Subject: Re: Single statment STRING to chars_ptr... how to? Date: 2000/03/15 Message-ID: <38CFD170.C8979F1D@mindspring.com>#1/1 X-Deja-AN: 597897314 Content-Transfer-Encoding: 7bit References: <38CE7BB6.C045C710@mindspring.com> <8ao96a$nk0$1@nnrp1.deja.com> To: dennison@telepath.com X-Accept-Language: en X-Server-Date: 15 Mar 2000 18:09:49 GMT Content-Type: text/plain; charset=us-ascii Organization: MindSpring Enterprises Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-03-15T18:09:49+00:00 List-Id: THANK YOU... I have been pounding my head against this for a day now... > The problem is that you are trying to create a pointer to a stack-based > copy of my_string (specificly, the copy passed by by interfaces.c.to_c). > That copy in all likelyhood ceases to exist as a valid object after the well, when you put it that way... :{ two quick points. 1) I am new to 95 and am simply trying to learn what to do and what not to do. 2) Our real code (being ported from 83 to 95 by me) uses system.address for all of the c interfaces. Some of these probably will work under gnat, some of them will not work (fat pointers), and some I just dont know about. In the case you responded to I am trying to find a replacement for a a single statement in our 83 code, preferably without having to write any subroutines of my own. Here is what the code looks like under 83: return mypkg.my_c_sub(mypkg.cstring_to_adastring(the_string)); where my_c_sub is written in c and imported, and the_string is just a normal ada string. a second case is mypkg.his_c_sub(mypkg.cstring_to_adastring(the_string)); For both of these cases I want the c routines (my_c_sub and his_c_sub) to have a "in" parameter of type interfaces.c.strings.chars_ptr; I know I am trying to have a pointer to memory on the stack, but I was expecting the compiler to be able to carry this construct back up the function returns. In the particular case of if.c.s.to_chars_ptr[if.c.to-c(S)'access] my intent was to have if.c.to-c(S) to return its value by VALUE, via the stack and have the outer function if.c.s.to_chars_ptr operate on that value, making a new thingie on the stack that it could then return by VALUE to its caller, which would then be still "living" in the scope of the caller. This type of thing is done all the time with arrays and structures... so I thought it could be done with some type of anonymous pointer type that would be created/distroyed as needed to propagate the data up the call list. the think on the stack that is pointed to is only there for the interface between two routines, so it lifetime should be okay... I thought I had seen code that did this type of thing. Well, that's what I was trying to do, and why I thought it would be okay... so, where am I going awry? By the way, the reason I was trying to use chars_ptr was I was familiar with it. As best as I can tell, using if.c.char_array is actually a better choice for the two "real code" cases I gave above. Still, I am try to learn the can's and cant's of chars_ptr, so I am still very interested in this. thanks for the help! -al