declaring arrays in prototypes

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

I thought that I had been through this before, but perhaps I'm forgetting what I did . Now I get "(27): error #2091: Missing array size."

If I put the array sizes in the prototypes, it also wants them in the actual function. This is Pelles C.

 

I vaguely remember using function prototypes like this before -- without putting in any sizes for the arrays.  I followed some reference and it was all good.

 

 

void sortlohi(int[][],int);
void std_dev(int[][],int,float[]);

 

The arrays are declared in main and passed to the function

 

int ddt_ctrm[2][5000];//combo  trim

float rslt[10]; //array to return std dev results

 

sortlohi((ddt_ctrm,lncnthi);

std_dev(ddt_ctrm,lncnthi,rslt);

 

void sortlohi(int data_4_sort[][],int count0)
    {
        //bubble sort

    }

    void std_dev(int data_4_sdev[][],int count,float rslt1[])
    {

    }

 

Thanks,

 

hj

 

 

 

 

 

 

Last Edited: Sun. Apr 14, 2019 - 02:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Never mind -- that's not true for multi dimensional arrays

 

hj

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As you'll have found you have to give every dimension but the last (which is then optional).

 

Of course you could just pass it as "int **" or, if you really want to defer interpretation, then void *

 

(Oh a classic piece of Autocorrect from Android, that must be schooled in MISRA, I typed "void *" and it gave me "avoid *"!!)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Of course you could just pass it as "int **

Actually what you would want is a 'pointer to an array of NUM_COLUMNS int'

eg.

#define ROWS 2
#define COLS 3

void array2d(int a[][COLS]) {}
or
void array2d(int (*a)[COLS]) {}

 

or you can do

void array2d(int a[ROWS][COLS]) {}

but ROWS is pretty meaningless