[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Gm2] Dynamic arrays?!?
From: |
Gaius Mulley |
Subject: |
Re: [Gm2] Dynamic arrays?!? |
Date: |
Sat, 19 Sep 2009 10:40:54 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
Martin Kalbfuß <address@hidden> writes:
> I'm a bit confused. You're talking about multidimensional dynamic arrays
> in the news. I don't get even a simple dynamic array working.
>
Hi Martin,
multidimensional dynamic array _parameters_ as per ISO. PIM[234]
defined the behaviour of uni dimensional dynamic array parameters.
So you can now:
PROCEDURE foo (a: ARRAY OF CHAR) ;
VAR
h: CARDINAL ;
BEGIN
h := HIGH(a)
END foo ;
as well as:
PROCEDURE bar (a: ARRAY OF ARRAY OF CHAR) ;
VAR
h: CARDINAL ;
BEGIN
h := HIGH(a[0])
END bar ;
> What's the way to go? ALLOCATE and pointer arithmetic? Or is there
> anything I missed? The resources on the net wasn't very helpfull at all.
yes this is probably the way to go if you want the equivalent of the GNU C
constructs:
char a[n];
or in C (without GNU extensions)
char *a = (char *)alloca(n);
then the equivalent in Modula-2 might be:
VAR
a: POINTER TO CHAR ;
BEGIN
ALLOCATE(a, n) ;
...
DEALLOCATE(a, n)
END
and you would have to manage the array arithmetic yourself though..
regards,
Gaius