comp.lang.ada
 help / color / mirror / Atom feed
From: eachus@spectre.mitre.org (Robert I. Eachus)
Subject: Re: Two questions
Date: 1996/11/08
Date: 1996-11-08T00:00:00+00:00	[thread overview]
Message-ID: <EACHUS.96Nov8180909@spectre.mitre.org> (raw)
In-Reply-To: 32825177.41C6@afit.af.mil


In article <32825177.41C6@afit.af.mil> Ding-yuan Sheu <dsheu@afit.af.mil> 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...




  parent reply	other threads:[~1996-11-08  0:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-11-07  0:00 Two questions Ding-yuan Sheu
1996-11-07  0:00 ` Robert Dewar
1996-11-08  0:00 ` Robert I. Eachus [this message]
1996-11-08  0:00 ` Norman H. Cohen
1996-11-08  0:00 ` Jon S Anthony
  -- strict thread matches above, loose matches on Subject: below --
2002-07-04 22:25 Mark
2002-07-04 22:40 ` Jeffrey Creem
2001-03-12 10:59 Christoph Grein
2001-03-12 17:43 ` Stephen Leake
2001-03-09 18:27 chris.danx
2001-03-09 20:22 ` Mark Lundquist
2001-03-09 20:56 ` Randy Brukardt
2001-03-12 15:36 ` John English
2001-03-12 18:11   ` chris.danx
1996-11-09  0:00 tmoran
1996-11-11  0:00 ` Adam Beneschan
1996-11-13  0:00 ` Richard A. O'Keefe
1996-05-01  0:00 Bernard Banner
1996-05-01  0:00 Ed Seidewitz
1996-05-01  0:00 W. Wesley Groleau (Wes)
1989-04-11 13:32 Piercarlo Grandi
1989-04-14 17:14 ` callen
1989-03-30 11:53 Piercarlo Grandi
1989-04-13  0:46 ` Paul Stachour
1989-03-29  9:16 HansM
1989-03-29 18:35 ` Michael Peirce
1989-03-31 13:10 ` stt
1989-03-31 18:59 ` Scott Simpson
1989-04-03 14:44 ` callen
replies disabled

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