Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can a function not have a Static parameter? [closed]

Tags:

c

The following is the code in c.

     fact(2);
     void fact(static int i)
     {..}

Output:Error cannot have static arguments
So why can't we have static arguments in a function?

like image 902
ghostrider Avatar asked Nov 16 '25 20:11

ghostrider


2 Answers

The static keyword means that a variable may have only and exactly one instance in its scope, and that instance is invisible out of its scope. Neither of these requirements make sense for a function argument: it may be called multiple times, at a different memory address, and as it's meant for communication, it has to be visible to the outer world.

Trying to apply static to an argument doesn't make much sense, so the standard doesn't allow it (§6.7.5.3/2: "The only storage-class specifier that shall occur in a parameter declaration is register.")

like image 44
Jerry Coffin Avatar answered Nov 19 '25 08:11

Jerry Coffin