storage class static of functions

J

jameskuyper

Chris said:
That's an interesting claim; to be clear, are you saying that

static void nuffin(void) {}

isn't legal, or are you saying that the notion of "storage class"
appropriate to variables isn't applicable to functions?

The latter. It's actually referred to as "storage duration" rather
than "storage class" in the standard. The result of applying the
'static' keyword to the definition of a variable is to give that
variable static storage duration. The result of applying the 'static'
keyword to the definition of a function is to give that function's
name internal linkage.
 
R

Ravishankar S

asit said:
Can functions have static storage clas ??
yes , they can.
If yes, what is it's advantage ??
the "advantages" , if one can call that , are:

the static keyword makes the functions local to the file (more accurately
"translation unit") in which it is defined. This means the function can be
called only within that fileTherefore it
1) Provides modularity by data hiding and
2) Gives an opportunity to the compiler to optimize better (by say inlining)

In certain cases a "static" "inline" function is a type-safe replacement for
a preprocessor macro.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top