Semicolon on a function parameters

If that's how you call it from C always (i.e. with n and m fixed at compile time) then in C++ you can do:

template <int N, int M>
void matrix_insert_values(const double (&a)[M][N]);

int main() {
  double in[5][3] = {
    { 12, -51,   4},
    {  6, 167, -68},
    { -4,  24, -41},
    { -1, 1, 0},
    { 2, 0, 3},
  };

  matrix_insert_values(in);
};

which has N and M as template parameters and these are deduced automatically at compile time from the input passed to the function.


It is a seldom-used feature from C99 GNU extension (GCC documentation) that is used to forward-declare parameters used in VLA declarators.

matrix_* matrix_insert_values(int n; double a[][n], int m, int n);

Do you see how int n appears twice? The first int n; is just a forward declaration of the actual int n, which is at the end. It has to appear before double a[][n] because n is used in the declaration of a. If you were okay with rearranging parameters, you could just put n before a and then you wouldn't need this feature

matrix_* matrix_insert_values_rearranged(int m, int n, double a[][n]);

Note about C++ compatibility

To be clear, the GNU extension is just the forward declaration of function parameters. The following prototype is standard C:

// standard C, but invalid C++
matrix_* matrix_insert_values_2(int m, int n, double a[][n]);

You cannot call this function from C++, because this code uses variable length arrays, which are not supported in C++. You would have to rewrite the function in order to be able to call it from C++.

Tags:

C++

C

Syntax

Matrix