comp.lang.ada
 help / color / mirror / Atom feed
* Another Newbie question about interfacing to C
@ 2000-06-01  0:00 David Gressett
  2000-06-01  0:00 ` gressett
  0 siblings, 1 reply; 3+ messages in thread
From: David Gressett @ 2000-06-01  0:00 UTC (permalink / raw)


I need to communucate with a C routine that takes an array of char *
as an argument, i.e., it is prototyped as

void someroutine(char *things[]);

The problem is that the component elements of  things are not
necessarily pointers to char;  they could be pointers to something
else that have been cast to pointers to char. someroutine has access
to information that tells it exactly which type is pointed to by the
elements of things[].

The original programmer of this routine used this technique to pass
arguments of arbitrary type to the routine someroutine. The types are
known at compile time, and their order in things[] is significant.The
number of elements in things[] is unlimited.

Is there a reasonable Ada way to pass arguments of arbitrary type to
an Ada routine? It need not look very C-ish. 




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

* Re: Another Newbie question about interfacing to C
  2000-06-01  0:00 Another Newbie question about interfacing to C David Gressett
@ 2000-06-01  0:00 ` gressett
  2000-06-02  0:00   ` Marin D. Condic
  0 siblings, 1 reply; 3+ messages in thread
From: gressett @ 2000-06-01  0:00 UTC (permalink / raw)


David Gressett <gressett@iglobal.net> wrote:

>I need to communucate with a C routine that takes an array of char *
>as an argument, i.e., it is prototyped as
>
>void someroutine(char *things[]);
>
>The problem is that the component elements of  things are not
>necessarily pointers to char;  they could be pointers to something
>else that have been cast to pointers to char. someroutine has access
>to information that tells it exactly which type is pointed to by the
>elements of things[].
>
>The original programmer of this routine used this technique to pass
>arguments of arbitrary type to the routine someroutine. The types are
>known at compile time, and their order in things[] is significant.The
>number of elements in things[] is unlimited.
>
>Is there a reasonable Ada way to pass arguments of arbitrary type to
>an Ada routine? It need not look very C-ish. 


Hmmm. Further study of the Cohen book causes me to believe that a
discriminant record type is what I need. It's interesting how C habits
can lead you into not seeing Ada stuff that is right under your nose.




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

* Re: Another Newbie question about interfacing to C
  2000-06-01  0:00 ` gressett
@ 2000-06-02  0:00   ` Marin D. Condic
  0 siblings, 0 replies; 3+ messages in thread
From: Marin D. Condic @ 2000-06-02  0:00 UTC (permalink / raw)


gressett@iglobal.net wrote:
> Hmmm. Further study of the Cohen book causes me to believe that a
> discriminant record type is what I need. It's interesting how C habits
> can lead you into not seeing Ada stuff that is right under your nose.

You might also try tagged records. You can declare some base type to be
tagged record and create an access type which will point to elements of
that class. Then anything you derive from that base type can be pointed
to by the access type. That way, you can create arrays of pointers that
will have heterogeneous collections of stuff. The routine you call to
process the stuff can then take advantage of dispatching to
automagically find the correct subprograms for processing the specific
items passed.

This may come a little closer in flavor to what you described than
discriminated records do. Hope this is helpful

MDC
-- 
======================================================================
Marin David Condic - Quadrus Corporation - http://www.quadruscorp.com/
Send Replies To: m c o n d i c @ q u a d r u s c o r p . c o m
Visit my web site at:  http://www.mcondic.com/

"Some people think programming Windows is like nailing jello to the 
ceiling... easy with the right kind of nails."

    --  Ivor Horton - Beginning Visual C++ 6
======================================================================




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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-01  0:00 Another Newbie question about interfacing to C David Gressett
2000-06-01  0:00 ` gressett
2000-06-02  0:00   ` Marin D. Condic

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