Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!csd.unb.ca!Gateway.UNB.ca
From:     GA4161@SIUCVMB.SIU.EDU
Sender:   APL Language Discussion <APL-L@UNBVM1.BITNET>
Reply-To: GA4161@SIUCVMB.SIU.EDU
Subject:  Re: C arrays, Jstructs, LinkJ
Message-ID: <APL-L%93050417142328@UNB.CA>
Organization: UofNB News Gateway, Fredericton, CANADA
Date:     Tue, 4 May 1993 15:09:49 CST

In article <1993May2.065705.22306@csus.edu> vpcsc4@sfsuvax1.sfsu.
(Emmett McLean) writes:
>Also I would like to
>know if it is possible to cast C arrays into the AV portion
>of A structs. (I've been using bcopy to transfer data ...

Because of the increasingly friendly interfaces to external
routines available in all APL's (does mov es, bx ring a bell?)
I think that Emmett has raised an important point in this post
and his earlier exchanges with Mr. Mullhaupt. Namely, what are
the most common forms of the vonNeumann strangle-hold and what
are the best accommadations of J/APL structures to them.

K&R write in _The C programming Language_: 'the main use of
arrays in C is to handle variable length string data' (I
paraphrase). Indeed! For the C compiler to resolve a memory
reference such as Xij it must be aware of the 'column'
dimension of the array X which requires the declaration of this
dimension at compile time. Run-time determination of an indexed
reference in two, or more, dimensions requires a computation no
less costly than your example macro.

With respect to the need to rewrite the C code your wish to use
as an external conjunction: it seems that you have identified a
large class of "toy" C code. But given this, one alternative
would be to leave the C code as is and simply trap for invalid
dimensions in the J argument while 'leaving as an exercise for
the energetic reader' the acceptable solution. In this form one
could simply change all declarations of the form 'Xmn;' to
'int *X = (int*)AV(y);' and pass X as an argument to a C function
with declaration like 'foo(int X10,...)'. Within 'foo' the
original Xij references would be valid.

WRT dynamic allocation of arrays: since it will be necessary to
compute indexed references at run-time anyway why not simply use
jma for allocations? At least that way you still have the option
of using J expressions within the C routines.

Mike Justesen
