1

I just saw a function with the following signature:

bool insert( Node** root, int (*M)[COL], int row, int col )

What does COL do in this case?

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
dazzphot
  • 307
  • 1
  • 3
  • 11
  • See [Multidimensional Arrays and Functions](http://www.eskimo.com/~scs/cclass/int/sx9a.html). – herohuyongtao Aug 17 '14 at 03:20
  • Consider the information in [Write a prototype for a C function that takes an array of exactly 16 integers](http://stackoverflow.com/questions/4710454/write-the-prototype-for-a-c-function-that-takes-an-array-of-exactly-16-integers/4710472#4710472). – Jonathan Leffler Aug 17 '14 at 06:01

1 Answers1

2

That's the array size. COL would have been #defined somewhere in code... Suppose COL is defined as 5, you are expected to provide a pointer to an array of 5 integers. Any other dimension would cause a compiler error.

For example.

#define COL 5
...
..
..

bool insert( Node** root, int (*M)[COL], int row, int col ) {

..
return 1;
}

...

And usage (in this case):

int test[5] = {0}; 
... 
insert(&node, &test, 0, 0);

Will Compile and :

int test[10] = {0};
...
insert(&node, &test, 0, 0); 

Will NOT compile...

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
  • You can also use `int arr[10][COL]; insert(&node, arr, 0, 0);`. – R Sahu Aug 17 '14 at 03:40
  • In the second case, `gcc` (4.8) and `clang` (3.5) both let you off with a warning, but compile the C program. If you attempt to compile it as a C++ program, you get a compilation error. – rici Aug 17 '14 at 05:40
  • Note that you could also have an enumeration: `enum { COL = 5 };` for example. – Jonathan Leffler Aug 17 '14 at 06:32