comp.lang.ada
 help / color / mirror / Atom feed
* Two questions
@ 1989-03-29  9:16 HansM
  1989-03-29 18:35 ` Michael Peirce
                   ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: HansM @ 1989-03-29  9:16 UTC (permalink / raw)


We are trying to understand Ada tasking and there are two things we fail to
understand:

1. When an exception is raised and not handled in a task body, the task
   is terminated and the exception is not further propagated, without
   notice (11.4.1.8).  Why is this?
   Is there a way to invoke the kind of traceback that occurs when an
   exception is propagated out of the main program?

2. When a task has completed its execution, termination is delayed until all
   dependent tasks have terminated (9.4.6).  As a result, our program
   fills up all memory with completed tasks unable to terminate.  Why is
   this?  Can something be done about it (without altering task dependency)?


We have the impression that Ada was designed to deal with a small
number of large tasks, whereas we are trying to create a large number
of small tasks.  Is this true?  Does it matter?

Can anybody enlighten us?

AdvTHANKSance

Hans Mulder		Sjouke Mauw
hm@uva.uucp		sjouke@uva.uucp
mcvax!uva!hm		mcvax!uva!sjouke

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1989-03-29  9:16 Two questions HansM
@ 1989-03-29 18:35 ` Michael Peirce
  1989-03-31 13:10 ` stt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 29+ messages in thread
From: Michael Peirce @ 1989-03-29 18:35 UTC (permalink / raw)


>2. When a task has completed its execution, termination is delayed until all
>   dependent tasks have terminated (9.4.6).  As a result, our program
>   fills up all memory with completed tasks unable to terminate.  Why is
>   this?  Can something be done about it (without altering task dependency)?
>
>
>We have the impression that Ada was designed to deal with a small
>number of large tasks, whereas we are trying to create a large number
>of small tasks.  Is this true?  Does it matter?
>

The way we dealt with this problem was to reuse our tasks.  We had
a situation where we wanted to dispatch a handler task for each incoming
request from the network. In Vax Ada, the tasks weren't removed from
memory until after the program exited the scope of the task declaration.
This meant that in our outter most scope, a terminated tasks' memory
was never reclaimed.  To solve this problem, we set up a task manager that 
kept a list of idle tasks and whenever a task was requested it would reuse 
one of these tasks first before creating a new one.  Of course, each task
ended up having some extra code at the beginning to handle initialization
and some at the end to handle returning itself to the free list.  This
overhead was minimal though.

With this type of scheme in place we were able to run our system for 
days or weeks at a time using "new" tasks for each message, but never
running into memory usage problems.  

-- michael

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
@ 1989-03-30 11:53 Piercarlo Grandi
  1989-04-13  0:46 ` Paul Stachour
  0 siblings, 1 reply; 29+ messages in thread
From: Piercarlo Grandi @ 1989-03-30 11:53 UTC (permalink / raw)


In article <9274@claris.com> peirce@claris.com (Michael Peirce) writes:
    >2. When a task has completed its execution, termination is delayed until all
    >   dependent tasks have terminated (9.4.6).  As a result, our program
    >   fills up all memory with completed tasks unable to terminate.  Why is
    >   this?  Can something be done about it (without altering task dependency)?
    >
    >
    >We have the impression that Ada was designed to deal with a small
    >number of large tasks, whereas we are trying to create a large number
    >of small tasks.  Is this true?  Does it matter?
    >
    
    The way we dealt with this problem was to reuse our tasks.  We had
    a situation where we wanted to dispatch a handler task for each incoming
    request from the network. In Vax Ada, the tasks weren't removed from
    memory until after the program exited the scope of the task declaration.

This is all nice and true, but of course hardly satisfactory. It essentially
defeats the idea of using dynamically created tasks. It is a style of
programming akin to that used in Concurrent Euclid or other languages
with only a static number of tasks configurable. The scheme though is
efficient and not too difficult to implement, and slightly more flexible.

There is another problem with Ada tasking, and it is well known to those
who know OS/MVS and IMS. When an Ada task takes a page fault, the entire
address space is suspended waiting for resolution of the page fault;
another Ada task is not redispatched, even if it could, because on virtually
all the Ada implementations I know of (notably the VMS one) the OS does not
know about Ada tasks at all. In other words, Ada tasking is not very good on
virtual memory systems if one wants to keep track of multiple external
events. The classic example is having a terminal monitor, with each terminal
served by its own task.

There are only two solutions, one fairly horrible, having a signal delivered
by the OS on a page fault to the in-address space scheduler, the second
and proper one is to have threads in the OS and associated Ada tasks with
the threads. Unfortunately the second one can be fairly expensive, many
systems have high overhead threads (e.g. OS/MVS).
-- 
Piercarlo "Peter" Grandi            |  ARPA: pcg%cs.aber.ac.uk@nss.cs.ucl.ac.uk
Dept of CS, UCW Aberystwyth         |  UUCP: ...!mcvax!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK  |  INET: pcg@cs.aber.ac.uk

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1989-03-29  9:16 Two questions 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
  3 siblings, 0 replies; 29+ messages in thread
From: stt @ 1989-03-31 13:10 UTC (permalink / raw)



1. The concept of "trace-back" is a compiler/run-time-system
feature.  It is certainly possible to convince a compiler
vendor to create some sort of debugging output on this
kind of task termination.  Alternatively, and more portably,
you can create an "exception when others=>" in all task bodies
to report appropriately the unexpected demise of a task.

2. It is certainly true that "masters" must wait for their
dependent tasks to terminate.  If you have a large number
of completed tasks all with the same master, this suggests
that perhaps your tasks should be structured so that they
are reusable.  That is, enclose the main operation of
a task in a large loop headed by an entry call (to some kind of
job manager, presumably) which receives the next job to do.
This saves repeatedly creating and terminating tasks,
both of which are frequently slow operations.
(The job manager may indicate the next job for the task is
to terminate itself, if it decides that there are more
server tasks than needed.)

It is possible to have the creator of the task *not* be
the master by using access types.  For tasks within objects
designated by access types, the master is the block/unit enclosing
the declaration of the access type.  In most cases, unchecked
deallocation of such objects-containing-tasks will reclaim
the storage associated with the task as soon as the task completes.

S. Tucker Taft
Intermetrics, Inc.
733 Concord Avenue
Cambridge, MA  02138

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1989-03-29  9:16 Two questions 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
  3 siblings, 0 replies; 29+ messages in thread
From: Scott Simpson @ 1989-03-31 18:59 UTC (permalink / raw)


In article <674@uva.UUCP> hm@uva.UUCP (Hans Mulder & Sjouke Mauw) writes:
>We are trying to understand Ada tasking and there are two things we fail to
>understand:
>
>1. When an exception is raised and not handled in a task body, the task
>   is terminated and the exception is not further propagated, without
>   notice (11.4.1.8).  Why is this?
>   Is there a way to invoke the kind of traceback that occurs when an
>   exception is propagated out of the main program?

From the Rationale (Section 14.4, page 325)

"Note that if the exception where propagated to the parent task, it would
mean that the child tasks could interfere asynchronously wihth their parent,
and it would also mean that these interferences could occur simultaneously,
with disastrous results."

I think asynchronous is the key word.
	Scott Simpson
	TRW Space and Defense Sector
	oberon!trwarcadia!simpson  		(UUCP)
	trwarcadia!simpson@oberon.usc.edu	(Internet)

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1989-03-29  9:16 Two questions HansM
                   ` (2 preceding siblings ...)
  1989-03-31 18:59 ` Scott Simpson
@ 1989-04-03 14:44 ` callen
  3 siblings, 0 replies; 29+ messages in thread
From: callen @ 1989-04-03 14:44 UTC (permalink / raw)



>There is another problem with Ada tasking, and it is well known to those
>who know OS/MVS and IMS. When an Ada task takes a page fault, the entire
>address space is suspended waiting for resolution of the page fault;
>another Ada task is not redispatched, even if it could, because on virtually
>all the Ada implementations I know of (notably the VMS one) the OS does not
>know about Ada tasks at all. In other words, Ada tasking is not very good on
>virtual memory systems if one wants to keep track of multiple external
>events. The classic example is having a terminal monitor, with each terminal
>served by its own task.

This behavior is dependent upon the Ada runtime system implementation. MVS
supports its own flavor of tasking, in which several tasks (threads of control)
run in the same address space. On a machine with more than one physical
processor (which is very common these days), several tasks in the same 
address space can run simultaneously on different processors. If one of the
tasks incurs a page fault, the other tasks do NOT wait.

So what you want to look for is an implementation that allows you to 
map Ada tasks to "true" MVS tasks. There are at least 2.

-- Jerry Callen
   Intermetrics, Inc.
   733 Concord Ave.
   Cambridge, MA 02138

   callen@inmet.inmet.com
   ...!uunet!inmet!callen

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
@ 1989-04-11 13:32 Piercarlo Grandi
  1989-04-14 17:14 ` callen
  0 siblings, 1 reply; 29+ messages in thread
From: Piercarlo Grandi @ 1989-04-11 13:32 UTC (permalink / raw)


In article <124000035@inmet> callen@inmet writes:
    
    >There is another problem with Ada tasking, and it is well known to those
    >who know OS/MVS and IMS. When an Ada task takes a page fault, the entire
    >address space is suspended waiting for resolution of the page fault;
    
    This behavior is dependent upon the Ada runtime system implementation. MVS
    supports its own flavor of tasking, in which several tasks (threads of control)
    run in the same address space. On a machine with more than one physical
    processor (which is very common these days), several tasks in the same 
    address space can run simultaneously on different processors. If one of the
    tasks incurs a page fault, the other tasks do NOT wait.

Unfortunately I do not have a multiprocessor MVS system :->.

However on this subject, I cited OS/MVS and IMS preceisely because the
problem has been solved within them; MVS has one of the few multithreading
facilities (if that is the right word :->) around, and among others PL/1 uses
it etc...
    
    So what you want to look for is an implementation that allows you to 
    map Ada tasks to "true" MVS tasks. There are at least 2.

Let me add though that if I were selling an Ada compiler for MVS, I would
not boast that it does have real multithreading because it maps Ada tasks
onto MVS tasks; I would keep it a closely guarded secret. Why?

Easy is the answer: it is fairly obvious that Ada tasking was designed to
support a very fine grain of tasking, such as associating tasks with a
buffer pool, etc... Too bad that MVS tasks have truly stupendous overheads.

IBM are the first to admit this; in an old (early seventies) issue of their
Systems Journal (devoted to explaining the new VS2, as it was then called)
they discuss how it was decided that the MVS kernel internally would not use
MVS tasks, but rather lightweight tasks, precisely because TCBs are too
expensive to use in a multithread program like MVS itself.  Also, there must
be some good reason for which the major IBM databases or communication
subsystems or transaction processing systems don't use TCBs...

Too bad that those two vendors that you cite as allowing you to map Ada
tasks to "true" MVS tasks did not take the trouble of duplicating the IMS or
CICS internal schedulers, that do get page fault signals from the MVS
kernel. By the way, there is a facility to get page fault signals also in VM,
precisely because it is used to run multithreaded operating systems, and
these when run under it do use them.

On the other hand I must admit that using MVS tasks for Ada tasks, while
being quite inappropriate to the Ada style of tasking, does have the
advantage of being able to run them on multiple processors, which a simple
page fault handling in address space scheduler cannot do.

Unles sof course the in address space scheduler runs as multiple MVS tasks
(it, not the Ada tasks it manages). I don't really remember well, but some
recent version of IMS may do that.

Summing up, I thoroughy agree with other posters that Ada really requires
a lightweight thread implementation, and most current operating systems
do not qualify, either because they do not have threads or because they
are not lightweight. And, let me add, wasn't Ada supposed to run on
embedded systems where all tasks are lightweight, and there is no notion
of address spaces, not to speak of paging? :-] :-]
-- 
Piercarlo "Peter" Grandi            |  ARPA: pcg%cs.aber.ac.uk@nss.cs.ucl.ac.uk
Dept of CS, UCW Aberystwyth         |  UUCP: ...!mcvax!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK  |  INET: pcg@cs.aber.ac.uk

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1989-03-30 11:53 Piercarlo Grandi
@ 1989-04-13  0:46 ` Paul Stachour
  0 siblings, 0 replies; 29+ messages in thread
From: Paul Stachour @ 1989-04-13  0:46 UTC (permalink / raw)


In article <796@aber-cs.UUCP> pcg@cs.aber.ac.uk (Piercarlo Grandi) writes:

> ....
>There is another problem with Ada tasking, and it is well known to those

*** Stop. Let's get the problem in the right place.  It is NOT a 
*** problem with Ada, but with the OS that is running Ada.

>who know OS/MVS and IMS. When an Ada task takes a page fault, the entire
>address space is suspended waiting for resolution of the page fault;
>another Ada task is not redispatched, even if it could, because on virtually
>all the Ada implementations I know of (notably the VMS one) the OS does not
>know about Ada tasks at all. 
>  ....
>There are only two solutions, one fairly horrible, having a signal delivered
>by the OS on a page fault to the in-address space scheduler, the second
>and proper one is to have threads in the OS and associated Ada tasks with
>the threads. Unfortunately the second one can be fairly expensive, many
>systems have high overhead threads (e.g. OS/MVS).
***  Stop.  There is at least a third solution.  In ancient, 
***  multi-processor batch-systems that had time-sharing grafted on,
***  such as Honeywell's GCOS3, the time-sharing monitor handled its
***  own sub-threads, such as deciding when things were dispatchable
***  when they were not and when to swap a subtask and ...
***  And it let the OS do the dispatching.
***  Substitute/time-sharing-monitor/Ada RSL/ and it's not too different.
***  In the past, we had a multi-processing CPU that could do the
***  equivalent of dispatching two "ready" Ada tasks within a single OS
***  process.  Today, you tell me that OS/MVS, VAX/VMS, and such ilk
***  cannot even dispatch one such ready task.  ...Sigh
***  ...Ugh   Isn't "progress" wonderful.

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1989-04-11 13:32 Piercarlo Grandi
@ 1989-04-14 17:14 ` callen
  0 siblings, 0 replies; 29+ messages in thread
From: callen @ 1989-04-14 17:14 UTC (permalink / raw)



>/* Written  9:32 am  Apr 11, 1989 by pcg@aber-cs.UUCP in inmet:comp.lang.ada */
>/* ---------- "Re: Two questions" ---------- */
>In article <124000035@inmet> callen@inmet writes:
>    
>    >There is another problem with Ada tasking, and it is well known to those
>    >who know OS/MVS and IMS. When an Ada task takes a page fault, the entire
>    >address space is suspended waiting for resolution of the page fault;
>    
>    On a machine with more than one physical
>    processor (which is very common these days), several tasks in the same 
>    address space can run simultaneously on different processors. If one of the
>    tasks incurs a page fault, the other tasks do NOT wait.
>
>Unfortunately I do not have a multiprocessor MVS system :->.

It doesn't matter; regardless of how many processors there are in the system,
MVS will allow other tasks to run while one is blocked for a page fault.

> <Comments about "true" MVS tasking being too expensive for Ada
>  tasks, and that IMS and CICS don't use tasking for that reason>
>
>Too bad that those two vendors that you cite as allowing you to map Ada
>tasks to "true" MVS tasks did not take the trouble of duplicating the IMS or
>CICS internal schedulers, that do get page fault signals from the MVS
>kernel.

IMS and CICS do NOT get page fault signals from MVS. They DO use their own
internal schedulers, but of very different flavors. IMS uses multiple
address spaces to achieve concurrency (and an address space is a much
"heavier" entity than a task within an address space); the idea is that
the terminals and databases are owned by a "control region" and the code
for each transaction runs in a "message processing region." The control
region does use "true" MVS tasks within itself to achieve concurrency.

CICS, on the other hand, uses a single address space AND a single task, and
then does its own scheduling in that single task. THIS IS A BAD PERFORMANCE
BOTTLENECK! The reason is precisely the one you described: a page fault
stops the entire region. In recent years CICS has acquired a facility
similar to the IMS message processing region, called MRO (Multiple Region
Option), to help with this problem (and other) problems, and has also
begun to use multitasking (for DB2 and VSAM file access).

In order to use the "page fault" option of the ESPIE macro (the macro
that sets up "trap" handlers) you must be "authorized." This means, in
MVS, allowed to enter supervisor state. Should every Ada program
any user writes to be allowed to enter supervisor state?

>On the other hand I must admit that using MVS tasks for Ada tasks, while
>being quite inappropriate to the Ada style of tasking, does have the
>advantage of being able to run them on multiple processors, which a simple
>page fault handling in address space scheduler cannot do.

Precisely. Since multiprocessors are rapidly becoming the norm for IBM
370 architecture machines, it is foolish not to exploit them. I think
that MVS tasks are QUITE appropriate for Ada tasking, if used judiciously.

>Summing up, I thoroughy agree with other posters that Ada really requires
>a lightweight thread implementation, and most current operating systems
>do not qualify, either because they do not have threads or because they
>are not lightweight. 

Right, but if "midweight" threads are what you've got, you use them. :-)

>And, let me add, wasn't Ada supposed to run on
>embedded systems where all tasks are lightweight, and there is no notion
>of address spaces, not to speak of paging? :-] :-]
 
Yeah, but the customer wants MVS, and the customer is always right. :-)

>Piercarlo "Peter" Grandi            |  ARPA: pcg%cs.aber.ac.uk@nss.cs.ucl.ac.uk
>Dept of CS, UCW Aberystwyth         |  UUCP: ...!mcvax!ukc!aber-cs!pcg
>Penglais, Aberystwyth SY23 3BZ, UK  |  INET: pcg@cs.aber.ac.uk

-- Jerry Callen
   Intermetrics, Inc.
   ...!uunet!inmet!callen
   callen@inmet.inmet.com

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Two questions
@ 1996-05-01  0:00 W. Wesley Groleau (Wes)
  0 siblings, 0 replies; 29+ messages in thread
From: W. Wesley Groleau (Wes) @ 1996-05-01  0:00 UTC (permalink / raw)



1. Anyone working on a HP-UX port of gnat?  He/She/They may be able to
use some code that I can provide.  I didn't write it, but I have
verified (with the help of the original anonymous author) that it
works.

2. Asked this on gnatlist a while ago, but I didn't see an answer,
so I'll try a wider audience...

I am trying to study some of the rts with ada2html, which chokes at
the gnatf stage.  I do not need a "working" gnat, so any tricks
that get the file(s) past gnatf are OK.  Anyone have such a workaround
for the following?

398 -> gnatf -gnatg -gnatv -x6 -v a-astaco.ads


GNAT Front End/XREF Tool Version 2.05 (C) Copyright NYU, 1992,1993,1994

Checking: a-astaco.ads  last modified at 95-11-29 04:24.00 GMT.
fatal error: runtime library configuration error
cannot locate "Root_Controlled" in file "s-finimp.ads" (entity not in package)
 41 lines: No errors
compilation of a-astaco.ads abandoned

--------------
Root_Controlled is defined, but in s-finroo.ads - and neither s-finroo nor
s-finimp are directly with'ed by s-astaco

Is there a CLI option to make gnatf show the dependency tree of files it
parsing?

--
---------------------------------------------------------------------------
W. Wesley Groleau (Wes)                                Office: 219-429-4923
Magnavox - Mail Stop 10-40                               Home: 219-471-7206
Fort Wayne,  IN   46808              elm (Unix): wwgrol@pseserv3.fw.hac.com
---------------------------------------------------------------------------




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
@ 1996-05-01  0:00 Ed Seidewitz
  0 siblings, 0 replies; 29+ messages in thread
From: Ed Seidewitz @ 1996-05-01  0:00 UTC (permalink / raw)



At 10:43 AM 5/1/96, W. Wesley Groleau (Wes) wrote:
>1. Anyone working on a HP-UX port of gnat?  He/She/They may be able to
>use some code that I can provide.  I didn't write it, but I have
>verified (with the help of the original anonymous author) that it
>works.

There has been an HP-PA port of GNAT 3.01 that I have been using for some
time. It is on the NYU FTP. It doesn't have tasking, though. Or are you
specifically looking for 3.03?

__________________________________________________________________________
Ed Seidewitz                              NASA Goddard Space Flight Center
<ed.seidewitz@gsfc.nasa.gov>              Code 552.3
(301)286-7631                             Greenbelt MD 20771
__________________________________________________________________________
For non-NASA business, please use: <seidewitz@acm.org>




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
@ 1996-05-01  0:00 Bernard Banner
  0 siblings, 0 replies; 29+ messages in thread
From: Bernard Banner @ 1996-05-01  0:00 UTC (permalink / raw)



GNAT 3.03 is available now for HP (at cs.nyu.edu/pub/gnat) and does have a
preliminary version of tasking support.

> At 10:43 AM 5/1/96, W. Wesley Groleau (Wes) wrote:
> >1. Anyone working on a HP-UX port of gnat?  He/She/They may be able to
> >use some code that I can provide.  I didn't write it, but I have
> >verified (with the help of the original anonymous author) that it
> >works.
>
> There has been an HP-PA port of GNAT 3.01 that I have been using for some
> time. It is on the NYU FTP. It doesn't have tasking, though. Or are you
> specifically looking for 3.03?
>
> __________________________________________________________________________
> Ed Seidewitz                              NASA Goddard Space Flight Center
> <ed.seidewitz@gsfc.nasa.gov>              Code 552.3
> (301)286-7631                             Greenbelt MD 20771
> __________________________________________________________________________
> For non-NASA business, please use: <seidewitz@acm.org>
>
>




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Two questions
@ 1996-11-07  0:00 Ding-yuan Sheu
  1996-11-07  0:00 ` Robert Dewar
                   ` (3 more replies)
  0 siblings, 4 replies; 29+ messages in thread
From: Ding-yuan Sheu @ 1996-11-07  0:00 UTC (permalink / raw)
  Cc: mkanko, kshomper, lawlis, dsheu


Hello All,
	I am converting a C++ application into Ada95 and ran into
two problems. If you know the answers, please let me know. I appreciate
your any help.

(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.

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.

(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:
void strcount(char *str)
{
   static int total =0;
   int count = 0;

   while (*str++) count++;
   total = total + count;
}

Whenever strcount is called, the value of total will not be reinitialize
to 0. It will preserve the value after it was called last time.
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? 
Any comments are welcomed. Thanks in advance.
======================================================================
Ding-yuan Sheu (Steven) | Student of Air Force Institute Technology
(513)233-2022           | for Master Degree of Computer System
dsheu@afit.af.mil       | Software Engineering Sequence




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1996-11-07  0:00 Ding-yuan Sheu
@ 1996-11-07  0:00 ` Robert Dewar
  1996-11-08  0:00 ` Robert I. Eachus
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 29+ messages in thread
From: Robert Dewar @ 1996-11-07  0:00 UTC (permalink / raw)



Ding-yuan Sheu asks

 I am converting a C++ application into Ada95 and ran into
 two problems. If you know the answers, please let me know. I appreciate
 your any help.

 (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?

Let me address the second question. Yes, of course, this can be done using
a package level variable in Ada. Your question makes me suspect that you
do not have a good understanding of package structure in Ada. This is a
very fundamental part of the language, and it if you are going to do a good
job of reengineering a C++ application into Ada, as opposed to a translation
at a minimal level that ends up with Ada code looking like C++, then it is
important to master the package concept.

Straight minimal translation of software seldom makes sense, but you can
use the occasion of translation to reengineer and improve the structure
of the original, taking advantage of the full capabilities of the target
language, but to be able to do that requires a good understanding of both
source and target languages. 

Try going to adahome and following links to some of the very nice online
tutorials, you may find these useful for learning more about Ada 95.

"Can I .. using a static variable in the subprogram:"

this is C terminology and C thinking, there is no such thing as a static
variable inside a subprogram in Ada.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1996-11-07  0:00 Ding-yuan Sheu
  1996-11-07  0:00 ` Robert Dewar
  1996-11-08  0:00 ` Robert I. Eachus
@ 1996-11-08  0:00 ` Norman H. Cohen
  1996-11-08  0:00 ` Jon S Anthony
  3 siblings, 0 replies; 29+ messages in thread
From: Norman H. Cohen @ 1996-11-08  0:00 UTC (permalink / raw)



Ding-yuan Sheu wrote:

> (1) Is there an easy way to achieve the same result of the C++ sprintf
> function in Ada? 

If you mean causing formatted output going to go to a string instead of
to an output file, the answer is yes, there are versions of Put in the
generic packages Ada.Text_IO.Integer_IO, Ada.Text_IO.Modular_IO,
Ada.Text_IO.Float_IO, and so forth, that take a string rather than a
file as a target.  However, details of formatting are determined by
optional parameters to Put rather than by a printf-style format string. 
Also, there is no Ada analog for C functions with a variable number of
arguments of mixed type.  If x and y are integers and you want to do the
equivalent of
sprintf(s,"%d %d",x,y), you must make two calls on Put and then
concatenate the results (first trimming leading blanks, if this is
important to you):

   Put (X_String, X);
   Put (Y_String, Y);
   Move (S, Trim (X_String, Left) & ' ' & Trim (X_String, Right));
      -- Move and Trim are from Ada.Strings.Fixed
 
> (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:
> void strcount(char *str)
> {
>    static int total =0;
>    int count = 0;
> 
>    while (*str++) count++;
>    total = total + count;
> }

Unlike C functions, Ada subprograms can be nested in an outer package or
subprogram.  Any variable that is to hold its value from one call on the
subprogram to the next should be declared in a construct surrounding the
subprogram.  For example:

package Character_Counts is
   procedure Count_Characters (Str: in String);
   function Total_Characters return Natural;
end Character_Counts;

package body Character_Counts is

   Total: Natural := 0;  
      -- Hidden from all parts of the program outside this package.
      -- Retains its value between calls on Count_Characters.

   procedure Count_Characters (Str: in String) is
   begin
      Total := Total + Str'Length;
   end Count_Characters;

   function Total_Characters return Natural is
   begin
      return Total;
   end Total_Characters;

end Character_Counts;

This example is not all that different from declaring a static variable
at the file level in C, but Ada also provides more flexibility, e.g.
declaring several subpackages in a single file to minimize the region of
the program in which the variable is visible, or enclosing a variable in
a surrounding SUBPROGRAM (in which case the variable holds its value
between calls on the inner subprogram that occur during one call on the
outer subprogram, but the variable ceases to exist each time the outer
subprogram returns).

-- 
Norman H. Cohen
mailto:ncohen@watson.ibm.com
http://www.research.ibm.com/people/n/ncohen




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1996-11-07  0:00 Ding-yuan Sheu
                   ` (2 preceding siblings ...)
  1996-11-08  0:00 ` Norman H. Cohen
@ 1996-11-08  0:00 ` Jon S Anthony
  3 siblings, 0 replies; 29+ messages in thread
From: Jon S Anthony @ 1996-11-08  0:00 UTC (permalink / raw)



In article <32825177.41C6@afit.af.mil> Ding-yuan Sheu <dsheu@afit.af.mil> writes:

> 	I am converting a C++ application into Ada95 and ran into
> two problems. If you know the answers, please let me know. I appreciate
> your any help.

Sounds good, ;^)

> (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.

The absolute simplest way is to import the thing.  There are many
other ways that have been discussed in depth (to death?) and these may
be in the FAQ.


> I work on my project on SGI machines. SGI provides some C++ library 
> binding for Ada programers.

One thing that is sure to work (well, as much as anything...) is to
call the sprintf from a simple wrapper which you hit with export C.
You can then import this function with the standard pragma Import(...,
C) and Interfaces stuff (see the Interfaces package).


> (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?

Look at package level variables.  These do what you want.  Actually, have
a go at the

"Ada95: A guide for C and C++ programmers":

http://www.adahome.com/Ammo/cpp2ada.html

Or just go to the Ada home page: http://www.adahome.com/

and click on "From C/C++ to Ada".

This is thing is really very good for folks in possition like yourself.

/Jon
-- 
Jon Anthony
Organon Motives, Inc.
Belmont, MA 02178
617.484.3383
jsa@organon.com





^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1996-11-07  0:00 Ding-yuan Sheu
  1996-11-07  0:00 ` Robert Dewar
@ 1996-11-08  0:00 ` Robert I. Eachus
  1996-11-08  0:00 ` Norman H. Cohen
  1996-11-08  0:00 ` Jon S Anthony
  3 siblings, 0 replies; 29+ messages in thread
From: Robert I. Eachus @ 1996-11-08  0:00 UTC (permalink / raw)



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...




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
@ 1996-11-09  0:00 tmoran
  1996-11-11  0:00 ` Adam Beneschan
  1996-11-13  0:00 ` Richard A. O'Keefe
  0 siblings, 2 replies; 29+ messages in thread
From: tmoran @ 1996-11-09  0:00 UTC (permalink / raw)



> (1) Is there an easy way to achieve the same result of the C++
> sprintf function in Ada?
The Ada idiom for
  char str[20];
  sprintf(&str, "variable %s = %d", name, x);
would be something like:
declare
  str:constant string := "variable " & name & " =" & integer'image(x);
begin
 ...
Or, since you can return whole strings from functions, you can have
 ... return "variable " & name & " =" & integer'image(x);




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1996-11-09  0:00 tmoran
@ 1996-11-11  0:00 ` Adam Beneschan
  1996-11-13  0:00 ` Richard A. O'Keefe
  1 sibling, 0 replies; 29+ messages in thread
From: Adam Beneschan @ 1996-11-11  0:00 UTC (permalink / raw)



In article <561dfo$h2g@news2.delphi.com> tmoran@bix.com writes:
 
 >The Ada idiom for
 >  char str[20];
 >  sprintf(&str, "variable %s = %d", name, x);
 >would be something like:
 >declare
 >  str:constant string := "variable " & name & " =" & integer'image(x);
 >begin
 > ...
 >Or, since you can return whole strings from functions, you can have
 > ... return "variable " & name & " =" & integer'image(x);

Well, not exactly.  Assuming "x" may contain any 32-bit value
including -2**31, there's not enough room in "str" in the C example to
hold everything.  So the true Ada idiom should be something like:

 declare
    str : constant string := "variable " & name & " =" & integer'image(x);
 begin
    Write_Trash_All_Over_Your_Stack;

I suspect this is an idiom that would be highly familiar to C
programmers. 


:)
                                -- Adam




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  1996-11-09  0:00 tmoran
  1996-11-11  0:00 ` Adam Beneschan
@ 1996-11-13  0:00 ` Richard A. O'Keefe
  1 sibling, 0 replies; 29+ messages in thread
From: Richard A. O'Keefe @ 1996-11-13  0:00 UTC (permalink / raw)



tmoran@bix.com writes:
>The Ada idiom for
>  char str[20];
>  sprintf(&str, "variable %s = %d", name, x);
>would be something like:
>declare
>  str:constant string := "variable " & name & " =" & integer'image(x);
>begin
> ...
>Or, since you can return whole strings from functions, you can have
> ... return "variable " & name & " =" & integer'image(x);

He doesn't point out that the C version has a _major_ bug which the
Ada version is completely free of:  sprintf() is vulnerable to buffer
overflow.  In this particular example, the string
	"variable %s = %d"
contains 12 non-NUL non-format-item characters.  sprintf() will write
a NUL to the buffer, so we have 20 - (12 + 1) = 7 characters to hold
both the name and the value.  If the value x is 100 and the name is
"foobar", you are out of luck.

The Ada version, in contrast, returns a string which is just the
right size to hold the answer.

There's one other difference, which is that to get an Ada equivalent
of %d you need Trim(Integer'Image(x)) to get rid of the leading blanks.
(There's a lot of string handling stuff in Ada 95.)

-- 
Mixed Member Proportional---a *great* way to vote!
Richard A. O'Keefe; http://www.cs.rmit.edu.au/%7Eok; RMIT Comp.Sci.




^ permalink raw reply	[flat|nested] 29+ messages in thread

* Two questions
@ 2001-03-09 18:27 chris.danx
  2001-03-09 20:22 ` Mark Lundquist
                   ` (2 more replies)
  0 siblings, 3 replies; 29+ messages in thread
From: chris.danx @ 2001-03-09 18:27 UTC (permalink / raw)


Hi,
    two questions, one on exceptions and one on objects or tagged types.

Where exactly can i put an exception handler?  I read in JE's book that you
can put them in loop ... end loop statements after an exit statement.  I
normally put handlers at the end of a routine, and i was supprised to find
you could put them elsewhere.  What i want to know is where else can i put
them?  In a while loop?  In a for loop?  In an if?  ... etc.

The second is to do with tagged types.  Sometimes it is suggested that you
put your 'create routine' -- the initialisation routine -- in a nested
package.  Others suggest putting it in the same package as the tagged type.

Example

package something_cool is

    type cool is tagged private;

    package constructor is

        procedure create (c : out cool; ... ... );

    end constructor;

    private
        ...
        ...

end something_cool;

or

package something_cool is

    type cool is tagged private;

    procedure create (c : out cool; ... ... );

    private
        ...
        ...

end something_cool;


What's the difference?  Where should i use method 1 and where should i use
method 2?


Thanks,
Chris Campbell





^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  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
  2 siblings, 0 replies; 29+ messages in thread
From: Mark Lundquist @ 2001-03-09 20:22 UTC (permalink / raw)



chris.danx <chris.danx@ntlworld.com> wrote in message
news:Eg9q6.4382$pR3.821782@news2-win.server.ntlworld.com...
> Hi,
>     two questions, one on exceptions and one on objects or tagged types.
>
> Where exactly can i put an exception handler?  I read in JE's book that
you
> can put them in loop ... end loop statements after an exit statement.

Huh?

> I  normally put handlers at the end of a routine, and i was supprised to
find
> you could put them elsewhere.  What i want to know is where else can i put
> them?  In a while loop?  In a for loop?  In an if?  ... etc.

From the Ada 95 syntax cross-reference:

    handled_sequence_of_statements
         accept_statement   9.5.2
         block_statement   5.6
         entry_body   9.5.2
         package_body   7.2
         subprogram_body   6.3
         task_body   9.1

Those are all the places!

>
> The second is to do with tagged types.  Sometimes it is suggested that you
> put your 'create routine' -- the initialisation routine -- in a nested
> package.

Yeah... I remember reading something like that somewhere too, but I don't
remember what that's all about.  Maybe somebody else does...?

Mark Lundquist
Rational Software






^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  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
  2 siblings, 0 replies; 29+ messages in thread
From: Randy Brukardt @ 2001-03-09 20:56 UTC (permalink / raw)


chris.danx wrote in message ...
>Hi,
>    two questions, one on exceptions and one on objects or tagged
types.
>
>Where exactly can i put an exception handler?  I read in JE's book that
you
>can put them in loop ... end loop statements after an exit statement.
I
>normally put handlers at the end of a routine, and i was supprised to
find
>you could put them elsewhere.  What i want to know is where else can i
put
>them?  In a while loop?  In a for loop?  In an if?  ... etc.


You can't add a handler to a loop, for instance. But, you can put an
exception handler on a block. And a block is a statement. So,
effectively, you can put an exception handler anywhere you can put a
statement.  For instance:

    loop
      begin
           <stuff..>
     exception
           ....
     end;
   end loop;


>The second is to do with tagged types.  Sometimes it is suggested that
you
>put your 'create routine' -- the initialisation routine -- in a nested
>package.  Others suggest putting it in the same package as the tagged
type.
>
>Example
>
>package something_cool is
>
>    type cool is tagged private;
>
>    package constructor is
>
>        procedure create (c : out cool; ... ... );
>
>    end constructor;
>
>    private
>        ...
>        ...
>
>end something_cool;
>
>or
>
>package something_cool is
>
>    type cool is tagged private;
>
>    procedure create (c : out cool; ... ... );
>
>    private
>        ...
>        ...
>
>end something_cool;
>
>
>What's the difference?  Where should i use method 1 and where should i
use
>method 2?


When you have the nested package, the constructor is not inherited when
the type is derived. (In RMese, it isn't a primitive operation of the
type.) Typically, each constructor has a separate set of parameters, and
you don't want the same parameters on the constructor for each type. Ada
95 doesn't let you delete operations that are inherited, so you have to
prevent them from being inherited in the first place.

The alternative (which we use in Claw) is to override *all* inherited
constructors, and either make them work or raise an exception. But that
only works well with a shallow inheritance structure; a deeper structure
could end up with dozens of useless constructors inherited.

            Randy.






^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
@ 2001-03-12 10:59 Christoph Grein
  2001-03-12 17:43 ` Stephen Leake
  0 siblings, 1 reply; 29+ messages in thread
From: Christoph Grein @ 2001-03-12 10:59 UTC (permalink / raw)
  To: comp.lang.ada

package something_cool is

    type cool is tagged private;
    
    function Create (P: in Some_Parameters) return Cool;    -- gets abstract on
                                                            -- derivation
    procedure Create (c : out cool; P: in Some_Parameters); -- does not get
                                                            -- abstract on
                                                            -- derivation
    package constructor is  -- nothing inside will be inherited

        procedure create (c : out cool; ... ... );

    end constructor;

private
        ...

end something_cool;

Thus make your choice. As Randy said, you can end with a bunch of useless 
constructors with the inherited ones.





^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  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
  2 siblings, 1 reply; 29+ messages in thread
From: John English @ 2001-03-12 15:36 UTC (permalink / raw)


"chris.danx" wrote:
> 
> Hi,
>     two questions, one on exceptions and one on objects or tagged types.
> 
> Where exactly can i put an exception handler?  I read in JE's book that you
> can put them in loop ... end loop statements after an exit statement.

You've misread the book then, or written "can" instead of "can't" by mistake...

>  I
> normally put handlers at the end of a routine, and i was supprised to find
> you could put them elsewhere.  What i want to know is where else can i put
> them?  In a while loop?  In a for loop?  In an if?  ... etc.

Inside a begin...end block (which can go inside a loop or whatever), e.g.
like this:

  loop
    begin
      Put("Enter an integer: ");
      Get(X);
      exit;     -- get out of loop if this line is reached
    exception
      when Constraint_Error | Data_Error =>
        Put_Line ("Error in input -- please try again");
        Skip_Line;       -- end up here if "Get" fails,
    end;                 -- so don't exit from the loop
  end loop;

(This is the example from p.40 of my book.)

> The second is to do with tagged types.  Sometimes it is suggested that you
> put your 'create routine' -- the initialisation routine -- in a nested
> package.  Others suggest putting it in the same package as the tagged type.
> 
> Example
> 
> package something_cool is
> 
>     type cool is tagged private;
> 
>     package constructor is
> 
>         procedure create (c : out cool; ... ... );
> 
>     end constructor;
> 
>     private
>         ...
>         ...
> 
> end something_cool;
> 
> or
> 
> package something_cool is
> 
>     type cool is tagged private;
> 
>     procedure create (c : out cool; ... ... );
> 
>     private
>         ...
>         ...
> 
> end something_cool;
> 
> What's the difference?  Where should i use method 1 and where should i use
> method 2?

Generally, use the first. If you use the second approach, "create"
is inherited by types derived from Cool, but it may well need extra
parameters for a derived type... so you end up with two versions of
Create, one with the old set of parameters (which will presumably do
incomplete initialisation) which you might call accidentally. The
second technique just avoids making Create a primitive of Cool, so
it isn't inherited. (This is discussed in section 14.6 of my book.)

-----------------------------------------------------------------
 John English              | mailto:je@brighton.ac.uk
 Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
 Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
 University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  2001-03-12 10:59 Christoph Grein
@ 2001-03-12 17:43 ` Stephen Leake
  0 siblings, 0 replies; 29+ messages in thread
From: Stephen Leake @ 2001-03-12 17:43 UTC (permalink / raw)


Christoph Grein <christoph.grein@eurocopter.de> writes:

> package something_cool is
> 
>     type cool is tagged private;
>     
>     function Create (P: in Some_Parameters) return Cool;    -- gets abstract on
>                                                             -- derivation
>     procedure Create (c : out cool; P: in Some_Parameters); -- does not get
>                                                             -- abstract on
>                                                             -- derivation
>     package constructor is  -- nothing inside will be inherited
> 
>         procedure create (c : out cool; ... ... );
> 
>     end constructor;
> 
> private
>         ...
> 
> end something_cool;
> 
> Thus make your choice. As Randy said, you can end with a bunch of useless 
> constructors with the inherited ones.

A bit more rationale:

If you declare the constructors directly in the main package, they are
"primitive operations of the type", and are thus inherited by derived
types. This is usually not appropriate, since constructors for derived
types will usually take more or different parameters.

Declaring the constructors in a nested package makes them _not_ be
primitive operations, so they are not inherited. 

Another option is to put them in a child package, but that means they
can't take advantage of whatever is declared in the main package body.

-- 
-- Stephe



^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  2001-03-12 15:36 ` John English
@ 2001-03-12 18:11   ` chris.danx
  0 siblings, 0 replies; 29+ messages in thread
From: chris.danx @ 2001-03-12 18:11 UTC (permalink / raw)


I misread it.

Thanks for your help,
Chris Campbell

"John English" <je@bton.ac.uk> wrote in message
news:3AACECE3.6D6E274E@bton.ac.uk...
> "chris.danx" wrote:
> >
> > Hi,
> >     two questions, one on exceptions and one on objects or tagged types.
> >
> > Where exactly can i put an exception handler?  I read in JE's book that
you
> > can put them in loop ... end loop statements after an exit statement.
>
> You've misread the book then, or written "can" instead of "can't" by
mistake...
>
> >  I
> > normally put handlers at the end of a routine, and i was supprised to
find
> > you could put them elsewhere.  What i want to know is where else can i
put
> > them?  In a while loop?  In a for loop?  In an if?  ... etc.
>
> Inside a begin...end block (which can go inside a loop or whatever), e.g.
> like this:
>
>   loop
>     begin
>       Put("Enter an integer: ");
>       Get(X);
>       exit;     -- get out of loop if this line is reached
>     exception
>       when Constraint_Error | Data_Error =>
>         Put_Line ("Error in input -- please try again");
>         Skip_Line;       -- end up here if "Get" fails,
>     end;                 -- so don't exit from the loop
>   end loop;
>
> (This is the example from p.40 of my book.)
>
> > The second is to do with tagged types.  Sometimes it is suggested that
you
> > put your 'create routine' -- the initialisation routine -- in a nested
> > package.  Others suggest putting it in the same package as the tagged
type.
> >
> > Example
> >
> > package something_cool is
> >
> >     type cool is tagged private;
> >
> >     package constructor is
> >
> >         procedure create (c : out cool; ... ... );
> >
> >     end constructor;
> >
> >     private
> >         ...
> >         ...
> >
> > end something_cool;
> >
> > or
> >
> > package something_cool is
> >
> >     type cool is tagged private;
> >
> >     procedure create (c : out cool; ... ... );
> >
> >     private
> >         ...
> >         ...
> >
> > end something_cool;
> >
> > What's the difference?  Where should i use method 1 and where should i
use
> > method 2?
>
> Generally, use the first. If you use the second approach, "create"
> is inherited by types derived from Cool, but it may well need extra
> parameters for a derived type... so you end up with two versions of
> Create, one with the old set of parameters (which will presumably do
> incomplete initialisation) which you might call accidentally. The
> second technique just avoids making Create a primitive of Cool, so
> it isn't inherited. (This is discussed in section 14.6 of my book.)
>
> -----------------------------------------------------------------
>  John English              | mailto:je@brighton.ac.uk
>  Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
>  Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
>  University of Brighton    |    -- see http://burks.bton.ac.uk
> -----------------------------------------------------------------





^ permalink raw reply	[flat|nested] 29+ messages in thread

* Two questions
@ 2002-07-04 22:25 Mark
  2002-07-04 22:40 ` Jeffrey Creem
  0 siblings, 1 reply; 29+ messages in thread
From: Mark @ 2002-07-04 22:25 UTC (permalink / raw)


Gents I'd like to do a GUI application in ADA.  The application will
be run on Solaris.  Is there a 'free' toolset I could start off with
that offers ease of use.  Rapid seems to be the only one.   In any
event, help.


Could someone provide sample code on accomplishing a task.  I have an
application where I want the user to enter up to 250 values max. 
Values are in the range 1 .. 65535.
So now the user will first tell me how many values he wants:  lets
assume the user wants 10 values.
My next question would be for user to enter the 10 values within the
range specified above.  I'll then store user defined values into an
array which I'll pass on to a function that'll take user defined
values and parse into 'hibyte versus lobyte'.   The function part i
can handle however,the user selection part I'm a bit confused about.

I'd like to also have the option to to use a random number generator. 
 This helps such that if the user watns 200 values.  I'll generate 200
random numbers within specified range.

So now my 'menu' would look like this:
  -- 1. How many numbers.  
  -- 2. Random Numbers or User defined
  -- 3. Store numbers into array.  
  -- 4. Pass numbers into function.

I could do all this in Visual C etc, but as i'm learning Ada I've
grown to like it and am now trying to perfect my Ada.

Thanks in advance



^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: Two questions
  2002-07-04 22:25 Mark
@ 2002-07-04 22:40 ` Jeffrey Creem
  0 siblings, 0 replies; 29+ messages in thread
From: Jeffrey Creem @ 2002-07-04 22:40 UTC (permalink / raw)


Look at :

gtkada.eu.org

You will have to download and install the gtk toolkit for solaris. Gtk has
gotten pretty tough to compile
(lot of packages) but it does go fairly smoothly.

On the plus side, future Solaris versions will include GNOME (www.gnome.com)
and thus
Gtk libraries. Also, to some extent, you application GUI code can run under
Windows
with the Gtk libraries that have been ported to that platform.

Get a copy of glade (glade.gnome.org). It is a gui builder that supports Gtk
(and GtkAda) and when
you are just starting out it makes things a lot easier.

Finally..Your message is a little confusing since you say you could use
Visual C? On Solaris? Hmm..


"Mark" <ma740988@pegasus.cc.ucf.edu> wrote in message
news:a5ae824.0207041425.671c1d02@posting.google.com...
> Gents I'd like to do a GUI application in ADA.  The application will
> be run on Solaris.  Is there a 'free' toolset I could start off with
> that offers ease of use.  Rapid seems to be the only one.   In any
> event, help.
>
>
> Could someone provide sample code on accomplishing a task.  I have an
> application where I want the user to enter up to 250 values max.
> Values are in the range 1 .. 65535.
> So now the user will first tell me how many values he wants:  lets
> assume the user wants 10 values.
> My next question would be for user to enter the 10 values within the
> range specified above.  I'll then store user defined values into an
> array which I'll pass on to a function that'll take user defined
> values and parse into 'hibyte versus lobyte'.   The function part i
> can handle however,the user selection part I'm a bit confused about.
>
> I'd like to also have the option to to use a random number generator.
>  This helps such that if the user watns 200 values.  I'll generate 200
> random numbers within specified range.
>
> So now my 'menu' would look like this:
>   -- 1. How many numbers.
>   -- 2. Random Numbers or User defined
>   -- 3. Store numbers into array.
>   -- 4. Pass numbers into function.
>
> I could do all this in Visual C etc, but as i'm learning Ada I've
> grown to like it and am now trying to perfect my Ada.
>
> Thanks in advance





^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2002-07-04 22:40 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1989-03-29  9:16 Two questions 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
  -- strict thread matches above, loose matches on Subject: below --
1989-03-30 11:53 Piercarlo Grandi
1989-04-13  0:46 ` Paul Stachour
1989-04-11 13:32 Piercarlo Grandi
1989-04-14 17:14 ` callen
1996-05-01  0:00 W. Wesley Groleau (Wes)
1996-05-01  0:00 Ed Seidewitz
1996-05-01  0:00 Bernard Banner
1996-11-07  0:00 Ding-yuan Sheu
1996-11-07  0:00 ` Robert Dewar
1996-11-08  0:00 ` Robert I. Eachus
1996-11-08  0:00 ` Norman H. Cohen
1996-11-08  0:00 ` Jon S Anthony
1996-11-09  0:00 tmoran
1996-11-11  0:00 ` Adam Beneschan
1996-11-13  0:00 ` Richard A. O'Keefe
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
2001-03-12 10:59 Christoph Grein
2001-03-12 17:43 ` Stephen Leake
2002-07-04 22:25 Mark
2002-07-04 22:40 ` Jeffrey Creem

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