2

I'm familiar with several uses for the keyword "static" in C:

The first use has to do with an entity's lifetime, the second and third uses have to do with an entity's visibility, the fourth use has to do with optimization, and it seems strange to me that one keyword would act so differently depending on where it is used. Is there some strange detail of how static is usually implemented in compilers that makes it easy for this one keyword to do all of the above? What is the underlying functionality that "static" provides which results in these varied behaviors?

adamj537
  • 677
  • 7
  • 14
  • 1
    I think this is mainly a result of avoiding introduction of new keywords to the language at all costs. – Austin Brunkhorst May 30 '18 at 21:45
  • Nothing to understand here. The language is designed this way. You may also ask why `to have` has so many meanings and functions in English. – 0___________ May 30 '18 at 21:48
  • Hey, `const` is another candidate. – Eugene Sh. May 30 '18 at 21:53
  • Unfortunately this answer is now closed and the duplicate is closed as well... C Committee tried to limit the introduction of new keywords for compatibility with existing code that used the keyword as an identifier. They tried to overwork or overload existing keywords as much as possible. – ouah May 30 '18 at 22:06
  • Quoting C Rationale document: *"Where possible, however, new features have been added by overloading existing keywords, as, for example, long double instead of extended. It is recognized that each added keyword will require some existing code that used it as an identifier to be rewritten. No meaningful programs are known to be quietly changed by adding the new keywords."* – ouah May 30 '18 at 22:07
  • They also admitted it causes some confusion for storage-class specifier. *"C89 separated from the overloaded keywords for storage classes the various concepts of scope, linkage, name space, and storage duration. This has traditionally been a major area of confusion."* – ouah May 30 '18 at 22:09
  • Decisions 1-3 were taken not by the C committee but by Kernighan and Ritchie. Unfortunately. Probably a mishmash of opinion and backwards compatibility. Off topic. – user207421 May 31 '18 at 00:13
  • Thanks for the informative comments! I understand that my question is a duplicate (oops!) but shouldn't one of the two questions be open for new answers? – adamj537 May 31 '18 at 00:21
  • Then you get to C++ and class members... :(( OP is right - there is too much keyword overloading in these languages:( – Martin James May 31 '18 at 07:56

0 Answers0