Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static keyword in function declaration can be missing in function definition?

I want to have a static function which I declare in my .c file before defining it:

//file a.c version 1
static int foo();
...
static int foo()
{
...
}

However, it seems that I can leave the static keyword out of the function definition and I get no compiler warnings... e.g.

//file a.c version 2
static int foo();
...
int foo()
{
...
}

Am I correct in assuming these two forms are exactly the same?
If so, why is this discrepancy allowed and which form should I use?

like image 733
Arrakis Avatar asked Mar 10 '11 14:03

Arrakis


1 Answers

Yes 7.1.1/6

A name declared in a namespace scope without a storage-class-specifier has external linkage unless it has internal linkage because of a previous declaration and provided it is not declared const.

See also the examples of 7.1.1/7

like image 142
AProgrammer Avatar answered Oct 16 '22 13:10

AProgrammer