Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between static function declaration in C

Tags:

c

function

static

What is the difference between the following declarations in C?

static int foo(){}
int static foo(){}

As I understand the first format is used and subscribed in text books while the second nonetheless seems to work as well. Are the declarations equivalent?

like image 533
Quiescent Avatar asked Dec 15 '22 20:12

Quiescent


2 Answers

They are the same but the first form is preferred:

(C99, 6.11.5p1) "The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature"

like image 85
ouah Avatar answered Jan 07 '23 04:01

ouah


When you run the functions you will get an error like " static declaration of foo follows non-static declaration ".

It is not correct in C to use static in this way because static functions are visible in only the file you created

like image 22
Ashok Avatar answered Jan 07 '23 05:01

Ashok