Why is there a static keyword before the ALL functions (except main ())?

I read some source code files in C and C ++ (mostly C) ... I know that the value of the static keyword means that static functions are functions that are visible only to other functions in one file. In another context, I read that it is useful to use static functions in cases where we do not want them to be used outside the file that they write ...

I read one source code file, as I mentioned earlier, and I saw that ALL functions (except the main one) were static ... Because there are no other additional files related to the main source code .c file (not even headers), it’s logical why should I put static in front of all functions? What should they be protected from when there is only one source file ?!

EDIT: IMHO I think these keywords are put in to make the code bigger and heavier.

+3
source share
6 answers

, , -, , - ( , ) , . API .

+5

extern ( ), , .

static, . , ; static . , , , , .

, .

+15

, .

. , . , , - strcpy().

, , .

+3

, , ( main()), , , . "extern" , , .

, . ; , , , , - , ( ".c" ".c" - , ).

GCC, :

gcc -m64 -Wall -Wextra -std=c99 -Wmissing-prototypes -Wstrict-prototypes

; -std=c89 -std=c99; -m32 -m64; -Wextra ( ). -Wmissing-prototypes -Wstrict-prototypes, , ​​ ( ). -Werror (, , ). , , - , .

, . , - , - , , , , .

+3

, . , - , .

+2

, .c ( ), ? , ?!

In this case, you do not need a keyword static.

EDIT: IMHO I think these keywords are only put in order to make the code look bigger and heavier.

However, if you really want to learn more about the key static, you can start with a book. Additional keyword information staticon # 2216239 - may help!

-1
source

Source: https://habr.com/ru/post/1731798/


All Articles