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,c4d884378fc6b03c X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: Two questions Date: 1996/11/08 Message-ID: #1/1 X-Deja-AN: 195375051 references: <32825177.41C6@afit.af.mil> organization: The Mitre Corp., Bedford, MA. newsgroups: comp.lang.ada Date: 1996-11-08T00:00:00+00:00 List-Id: In article <32825177.41C6@afit.af.mil> Ding-yuan Sheu writes: > (1) Is there an easy way to achieve the same result of the C++ > sprintf function in Ada? I know this may be a FAQ. Your patience > and kindness are appreciated. Text_IO also provides Get and Put operations on strings, see your reference manual. > I work on my project on SGI machines. SGI provides some C++ > library binding for Ada programers. However, for the sprintf > function, I think the binding interface is unclear. So, I don't > know how to use it. If you happen to know how to use it. Please > let me know. Don't. The overhead of converting Ada strings to C strings will overcome any advantage to using sprintf instead of the standard Ada routines. Actually you could build "wrappers" that did the conversions if you have many calls to sprintf with the same profile. But usually you don't have enough calls using any particular set of parameters for this approach to be worthwile. > (2) In a C++ function, prorammers can declare a static local variable > to preserve its value between function calls. Can I do that in Ada? > For example, in C++, I can write a function as follows... > I know I can use a package to wrap strcount and declare a private > variable in the package to achieve the same result. However, is this the > only solution? Can I simply declare a static variable in the Ada > subprogram to achieve the same result? Yes and no. There are other ways in Ada to accomplish this, but in general variables declared in the outer scope of library packages are the normal equivalent of static in C, Algol, or PL/I. There are other methods to obtain the same effect using tasks or protected objects, but that is like swatting flies with a sledgehammer. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...