Hi,

I'm doing a bit of C programming to speed up some of my function evaluations. I'm a bit confused about how arrays are passed to C function. In the `dllcall`

help file it says:

In C syntax, `func`

should take one of the following forms:

`int func(void);`

`int func(double *arg1 [, arg2...argN]);`

`int func(double *arg[]);`

I usually use form 2, but each `*arg`

can only be a vector. I was wondering if there is any way to pass a matrix as a multidimensional array into the C function? Also, how does form 3 work? For example, in this C program:

```
__declspec(dllexport) int copyAtoB(double *A, double *B, double *ele)
{
int i, j, n;
n=(int)ele[0];
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
B[i] = A[i];
}
}
return 0;
}
```

Can I somehow stack all my inputs to a ele-by-3 matrix M = { A; B; ele 0 0 0... } and pass it to a C function using form 3?

Many thanks. Fred

## 2 Answers

0

Sry about a mistake in the example program above.. The example should be:

```
__declspec(dllexport) int copyAtoB(double *A, double *B, double *ele)
{
int i, j, n;
n=(int)ele[0]
for (i = 0; i < n; i++)
{
B[i] = A[i];
}
return 0;
}
```

0

The 3rd form requires the '-v' flag passed to dllcall which will pass the arguments as a vector of double pointers.

The double pointer after the last valid argument will be set to NULL so the number of arguments can be attained. (instead of passing it in directly)

```
__declspec(dllexport) int copyAtoB(double *vars[])
{
int n, i;
n=(int)(vars[0][0]);
for (i = 0; i < n; i++)
{
vars[2][i] = vars[1][i]; // B[i] = A[i];
}
return 0;
}
```

and called by GAUSS

```
A = seqa(5,1,5);
B = seqa(1,1,5);
n = rows(A);
dllcall -v copyAtoB(n, A, B);
```

## Your Answer

## 2 Answers

Sry about a mistake in the example program above.. The example should be:

```
__declspec(dllexport) int copyAtoB(double *A, double *B, double *ele)
{
int i, j, n;
n=(int)ele[0]
for (i = 0; i < n; i++)
{
B[i] = A[i];
}
return 0;
}
```

The 3rd form requires the '-v' flag passed to dllcall which will pass the arguments as a vector of double pointers.

The double pointer after the last valid argument will be set to NULL so the number of arguments can be attained. (instead of passing it in directly)

```
__declspec(dllexport) int copyAtoB(double *vars[])
{
int n, i;
n=(int)(vars[0][0]);
for (i = 0; i < n; i++)
{
vars[2][i] = vars[1][i]; // B[i] = A[i];
}
return 0;
}
```

and called by GAUSS

```
A = seqa(5,1,5);
B = seqa(1,1,5);
n = rows(A);
dllcall -v copyAtoB(n, A, B);
```