Search code examples
staticfunction-pointers

Confusion about static function pointer in c


Look at the the following code snippet. It was written in 2005 but I am compiling it with latest gcc.

xln_merge_nodes_without_lindo(coeff, cand_node_array, match1_array, match2_array)
  sm_matrix *coeff;
  array_t *cand_node_array, *match1_array, *match2_array;
{ 
  node_t *n1, *n2;
  sm_row *row1, *row2;
  static sm_row *xln_merge_find_neighbor_of_row1_with_minimum_neighbors();

  while (TRUE) {
      row1 = sm_shortest_row(coeff);
      if (row1 == NIL (sm_row)) return;
      n1 = array_fetch(node_t *, cand_node_array, row1->row_num);
      row2 = xln_merge_find_neighbor_of_row1_with_minimum_neighbors(row1, coeff);
      n2 = array_fetch(node_t *, cand_node_array, row2->row_num);
      array_insert_last(node_t *, match1_array, n1);
      array_insert_last(node_t *, match2_array, n2);
      xln_merge_update_neighbor_info(coeff, row1, row2);
  }
}

While compiling,it complains,

xln_merge.c:299:18: error: invalid storage class for function ‘xln_merge_find_neighbor_of_row1_with_minimum_neighbors’

(xln_merger.c:299 is line 3 here after definition starts).

Line 3 function definition seems to be a function declaration (isn't it???). Does the programmer intended to write a function pointer (static)? Or some syntax has changed over the time in c why this is not compiling.

This code is from sis package here


Solution

  • Though uncommon, it's completely valid and standard to declare a function inside another one. However the static modifier makes no sense in a declaration without a body, and you can't* define your function inside another function.

    Does the programmer intended to write a function pointer (static)?

    I can't know the original programmer's intentions but in no way can that be a function pointer since there's no assignment to it.


    * Actually you can as a GCC extension