function name with static keyword

Thread Starter

anukalp

Joined Jul 28, 2018
158
The static keyword is a bit strange When it is placed in front of the variable, the variable is initialized only once and will remain alive until the program runs.

C:
#include<stdio.h>

static void foo (void)
{
    printf(" do something \n");
}

int main(void)
{
    foo();
    return 0;
}
I don't understand what happens if static keyword use in front of the function name ?
 

WBahn

Joined Mar 31, 2012
29,979
The static keyword is a bit strange When it is placed in front of the variable, the variable is initialized only once and will remain alive until the program runs.

C:
#include<stdio.h>

static void foo (void)
{
    printf(" do something \n");
}

int main(void)
{
    foo();
    return 0;
}
I don't understand what happens if static keyword use in front of the function name ?
A static function or a static global variable is accessible only within the file it is defined in.

I agree -- the static keyword means very different things depending on the context of use. I think that was a big mistake on the part of the language designers and for just this reason -- people learn what it means in one context and naturally try to apply that understanding to the others when they come across them.
 

ApacheKid

Joined Jan 12, 2015
1,533
The very term "static" originated I think in the PL/I language. The guys that developed C and Unix had already worked with PL/I on the Multics OS and there are a few things they borrowed (but they should have borrowed more!).

PL/I was a superb language at the time, C is almost embarrassing in contrast, PL/I was much better for system software (it had bit data types for example so you could declare structures of bits as aligned or unaligned and actually have the bits or even arrays of bits literally span the bits in a memory word very easily).

The term static is one, the /* and */ for comments is another.

We'd all have been using some derivative of PL/I if Digital Research had played their cards right with the IBM PC, Gary Kildall actually had a reasonable PL/I compiler running on CP/M which could have been the dominant OS for the PC, alas it was not to be.
 
Top