Another Newbie question about interfacing to C 
Author Message
 Another Newbie question about interfacing to C

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.



Mon, 18 Nov 2002 03:00:00 GMT  
 Another Newbie question about interfacing to C

Quote:

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


Mon, 18 Nov 2002 03:00:00 GMT  
 Another Newbie question about interfacing to C

Quote:

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

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



Tue, 19 Nov 2002 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. newbie question: implementation inheritance and interface specifications in Haskell 98

2. Newbie question about interface to C

3. Newbie question: XT keyboard interface

4. newbie-question: interfaces

5. newbie question RE which interface to SQL database to use

6. newbie question in Tk's interface to C/C++

7. Newbie question about Alien interface in CMUCL

8. Newbie question reguarding C program with TCL/TK interface

9. Newbie question: ST interface to C/C++?

10. Data Interface with CS/3

11. Newbie Question (Was: Newbie Question...)

12. to CS: or not to CS: in F-PC assembler

 

 
Powered by phpBB® Forum Software