comp.lang.ada
 help / color / mirror / Atom feed
* Multi-dimensional Array of Functions ?
@ 2000-05-04  0:00 John O'Malley
  2000-05-05  0:00 ` Ted Dennison
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: John O'Malley @ 2000-05-04  0:00 UTC (permalink / raw)


I am a newbie to ada and I am looking for an example of an
array of functions. The project I am currently working on
has a procedure which is a gaint case statement with nested
cases that make function calls. This procedure is
unreadable and could easily be reduced by 99% by using a
multidimensional array containing pointers to functions.

I know how to create an array of pointers to functions in C
and I was wondering if this is even possible in ada 83 or
95. If it is possible, do all the functions in the array
have to be formatted the same (i.e same pass and return
parameters)? Any help and/or examples would be appreciated.

Thanks,

John


* Sent from AltaVista http://www.altavista.com Where you can also find related Web Pages, Images, Audios, Videos, News, and Shopping.  Smart is Beautiful




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

* Re: Multi-dimensional Array of Functions ?
  2000-05-04  0:00 Multi-dimensional Array of Functions ? John O'Malley
  2000-05-05  0:00 ` Ted Dennison
  2000-05-05  0:00 ` Jim Rogers
@ 2000-05-05  0:00 ` Alfred Hilscher
  2 siblings, 0 replies; 4+ messages in thread
From: Alfred Hilscher @ 2000-05-05  0:00 UTC (permalink / raw)




John O'Malley wrote:
> 
> I am a newbie to ada and I am looking for an example of an
> array of functions. The project I am currently working on
> has a procedure which is a gaint case statement with nested
> cases that make function calls. This procedure is
> unreadable and could easily be reduced by 99% by using a
> multidimensional array containing pointers to functions.

You want put C code to Ada ? Did you think about whether there would be
a possiblilty to do it more "Ada like" ?
 
> I know how to create an array of pointers to functions in C
> and I was wondering if this is even possible in ada 83 or

It should be.

> 95. If it is possible, do all the functions in the array
> have to be formatted the same (i.e same pass and return
> parameters)?

Yes.

> Any help and/or examples would be appreciated.

Look into the archives in Dejanews. There was a similar question a few
weeks ago.
 
> Thanks,
> 
> John




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

* Re: Multi-dimensional Array of Functions ?
  2000-05-04  0:00 Multi-dimensional Array of Functions ? John O'Malley
  2000-05-05  0:00 ` Ted Dennison
@ 2000-05-05  0:00 ` Jim Rogers
  2000-05-05  0:00 ` Alfred Hilscher
  2 siblings, 0 replies; 4+ messages in thread
From: Jim Rogers @ 2000-05-05  0:00 UTC (permalink / raw)


In article <169b2ded.062ddfc5@usw-ex0109-068.remarq.com>,
  John O'Malley <john.omalleyNOjoSPAM@hs.utc.com.invalid> wrote:
> I am a newbie to ada and I am looking for an example of an
> array of functions. The project I am currently working on
> has a procedure which is a gaint case statement with nested
> cases that make function calls. This procedure is
> unreadable and could easily be reduced by 99% by using a
> multidimensional array containing pointers to functions.
>
> I know how to create an array of pointers to functions in C
> and I was wondering if this is even possible in ada 83 or
> 95. If it is possible, do all the functions in the array
> have to be formatted the same (i.e same pass and return
> parameters)? Any help and/or examples would be appreciated.
>
> Thanks,
>
> John

I think you may want to rethink the problem.

This looks like a strong candidate for polymorphism.
It appears that your C solution is very close to the C++
Vtbl solution. If so, you will simplify the readability of
the code more by using inheritance and tagged types than
by using a multidimensional array of function access types.

Jim Rogers
Colorado Springs, Colorado USA


Sent via Deja.com http://www.deja.com/
Before you buy.




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

* Re: Multi-dimensional Array of Functions ?
  2000-05-04  0:00 Multi-dimensional Array of Functions ? John O'Malley
@ 2000-05-05  0:00 ` Ted Dennison
  2000-05-05  0:00 ` Jim Rogers
  2000-05-05  0:00 ` Alfred Hilscher
  2 siblings, 0 replies; 4+ messages in thread
From: Ted Dennison @ 2000-05-05  0:00 UTC (permalink / raw)


In article <169b2ded.062ddfc5@usw-ex0109-068.remarq.com>,
  John O'Malley <john.omalleyNOjoSPAM@hs.utc.com.invalid> wrote:
> I am a newbie to ada and I am looking for an example of an
> array of functions. The project I am currently working on
> has a procedure which is a gaint case statement with nested
> cases that make function calls. This procedure is
> unreadable and could easily be reduced by 99% by using a
> multidimensional array containing pointers to functions.

Often the case statement can be removed entirely using dynamic
dispatching. See if there's a way to make a tagged type with a
predefined function and one child type per case branch. Then you can
just have Ada dispatch to the appropriate function based on which
subtype of the parent tagged type was passed in.

> I know how to create an array of pointers to functions in C
> and I was wondering if this is even possible in ada 83 or
> 95. If it is possible, do all the functions in the array
> have to be formatted the same (i.e same pass and return
> parameters)? Any help and/or examples would be appreciated.

Its possible in Ada 95. Get out your handy-dandy Ada 95 book (whichever
one you are using) and look up access to subprogram types.

--
T.E.D.

http://www.telepath.com/~dennison/Ted/TED.html


Sent via Deja.com http://www.deja.com/
Before you buy.




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

end of thread, other threads:[~2000-05-05  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-04  0:00 Multi-dimensional Array of Functions ? John O'Malley
2000-05-05  0:00 ` Ted Dennison
2000-05-05  0:00 ` Jim Rogers
2000-05-05  0:00 ` Alfred Hilscher

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