----- Original Message -----
From: "Sisyphus" <[EMAIL PROTECTED]>


> Hi,
> How does one retrieve the size of (number of elements contained in) such
an
> item ?
>
> 'sizeof' works nicely on static arrays, but I've not been able to get
> anywhere with it in regard to arrays dynamically allocated with Newz or
> arrays that have been Renew'd.


As I understand it, sizeof() is an operator that's value is determined at
compile time, so you cannot use it to determine the size of a dynamically
allocated array, or rather, an array whos size is determined after
compilation.  What you have to do is pass the size of the array as an
argument to the function which needs to kow its size.  it seems really
backwards coming from perl, but it is more efficient =)

e.g.:

    char * somefunc(char * array, int size) {

        char *array_2;
        int cntr = size -1;
        int i;

        Newz(0, array_2, size, char);

        for (i = 0; i <= cntr; i++) {
            array_2[i] = array[i] + 1;
            }

        return(array_2);
    }

HTH,

!c

C. Church
http://www.digitalKOMA.com/church/
http://www.DroneColony.com/


Reply via email to