Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!nott!uotcsi2!news
From: cbbrowne@csi.uottawa.ca (Christopher Browne)
Subject: Re: C arrays, J structs, and LinkJ
Message-ID: <1993May2.174517.11682@csi.uottawa.ca>
Keywords: C, J
Sender: news@csi.uottawa.ca
Nntp-Posting-Host: prgb
Organization: Dept. of Computer Science, University of Ottawa
References: <1993May2.065705.22306@csus.edu>
Date: Sun, 2 May 93 17:45:17 GMT

In article <1993May2.065705.22306@csus.edu> vpcsc4@sfsuvax1.sfsu.edu (Emmett McLean) writes:
>
>One of the difficulties I've run into when porting programs to
>10!:k is that often the original usage of the C program uses
>multidimensional array declarations such as "int d[10][10]"
>which assumes that the number of columns (and rows) are known 
>at compile time. I would like to know if arrays of the type
>int[][] can be allocated memory dynamically. 

Simple answer: Yes.

Try the following C function:

void allocd (int **d, int rows, int cols)
{
  int i;
  /* It's fairly possible that I may have rows and cols mixed up; this */
  /* may actually produce d transpose.  If so, then swap rows and */
  /* cols. */
     
  d = (int **) malloc(cols * sizeof(int *));
  for (i = 0; i < cols; i ++)
    d[i] = (int *) malloc(rows * sizeof(int));
}

correspondingly, we get:

void freed (int **d, int cols)
{
  for (i = 0 ; i < cols ; i++)
    free(d[i]);
  free(d);
}

This stuff is copied nearly verbatim from some working code that I
  wrote over the past year.

>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 back
>and forth which seems inefficient.)

I'll have to give a big "Huh?" and head over to my J sources to
see just what AV and A are supposed to mean.

Probable answer is "yes," but I'll just have to check.
-- 
Christopher Browne                |     PGP 2.0 key available
cbbrowne@csi.uottawa.ca           |======================================
University of Ottawa              | Genius may have its limitations, but
Master of System Science Program  | stupidity is not thus handicapped.
