Confusion about static function pointer in c

Take a look at the following code snippet. It was written in 2005, but I collect it with the 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); } } 

When compiling, he 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 the start of the definition).

The definition of the function of line 3 seems to be a function declaration (isn't it?). Did the programmer intend to write a function pointer (static)? Or some kind of syntax has changed over time in c, why is this not compiling.

This code is from sis package here

+4
source share
3 answers

Despite being unusual, it is perfectly valid and standard to declare a function inside another. However, a static modifier does not make sense in a declaration without a body, and you cannot * define your function inside another function.

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

I cannot know the initial intentions of the programmer, but in no way can it be a pointer to a function, since there is no purpose for it.


* In fact, you can as a GCC extension

+2
source

At least for GCC, it will provide an "invalid storage class for function" if there is a broken declaration in the included file. You might want to go back to your header files and see what was intended for the declaration, and instead a hanging function, for example, the attached file xxx.h:

 void foo(int stuff){ <<<<<<<<< this is the problem, replace { with ; void bar(uint other stuff); 

an open "{" really confuses GCC and will cause random errors last. It is very easy to make a copy and past of the function and forget to replace {with a;
Especially if you use my favorite 1TBS

+8
source

I had the same problem as in the error message:

 libvlc.c:507:11: warning: "/*" within comment libvlc.c:2154: error: invalid storage class for function 'AddIntfInternal' libvlc.c:2214: error: invalid storage class for function 'SetLanguage' libvlc.c:2281: error: invalid storage class for function 'GetFilenames' libvlc.c:2331: error: invalid storage class for function 'Help' libvlc.c:2363: error: invalid storage class for function 'Usage' libvlc.c:2647: error: invalid storage class for function 'ListModules' libvlc.c:2694: error: invalid storage class for function 'Version' libvlc.c:2773: error: invalid storage class for function 'ConsoleWidth' libvlc.c:2808: error: invalid storage class for function 'VerboseCallback' libvlc.c:2824: error: invalid storage class for function 'InitDeviceValues' libvlc.c:2910: error: expected declaration or statement at end of input 

A simple fix for this problem: "there is some kind of bracket in the file from which I get these errors."

Just go to the example below.

For instance:

 #include<stdio.h> int test1() { int a = 2; if ( a == 10) { } 

will give

 test.c:7: error: expected declaration or statement at end of input 

After errors "invalid storage class for function".

So, just keeping the watch in braces can probably solve this error.

+8
source

All Articles