Home > Mobile >  Does C have 32 or 44 keywords?
Does C have 32 or 44 keywords?

Time:12-23

ISO/IEC 9899:2017 C N2176 document link: https://files.lhmouse.com/standards/ISO C N2176.pdf

There are plenty of sources on world wide web, which say that there are 32 keywords in C langauge, But this document (I think it's a draft version, but there's no much changes as compared to the previous version, right?) has 44 words that are defined to the keywords of C language.

Please explain this.

============================================================

Link to the sources which say that there are 32 keywords in C language:

  1. https://www.programiz.com/c-programming/list-all-keywords-c-language
  2. https://tutorials.webencyclop.com/c-language/c-keyword/
  3. https://www.educba.com/c-keywords/
  4. https://www.javatpoint.com/keywords-in-c
  5. https://beginnersbook.com/2014/01/c-keywords-reserved-words/
  6. https://www.phptpoint.com/c-keywords/
  7. https://www.guru99.com/c-tokens-keywords-identifier.html
  8. https://fresh2refresh.com/c-programming/c-tokens-identifiers-keywords/
  9. https://www.w3schools.in/c-tutorial/keywords/

Note: Some of these sites are useful for beginners to learn basic concepts and terminalogies of C.

CodePudding user response:

  • The claims of there being "32" keywords in C refer to the original ANSI-specified version of C from 1989, aka C89.
    • Because this is the Internet, and because the real C specifications are behind ISO's ridiculous paywall most people so-inclined probably can't fact-check the claim.
    • And it's not a claim worth fact-checking: the number of keywords in a language is utter trivia of no consequence.
  • The ISO/IEC 9899 specification you linked to refers to C17 (the proposed updated C specification in 2017) which postdates C89 by 28 years.
  • It should come as no surprise that a future updated revision of a programming language introduces new keywords.

Historically, when C was introduced, people were impressed by its minimalist syntax and how the language's design effectively reified everything by implementing functionality as library features instead of language features which is what keeps C simple and helps mitigate every language's designer's fears about feature creep.

In comparison, C's early contemporaries like COBOL, opted to implement functionality into their own languages as first-class features, which is why COBOL has over 300 keywords; so I'll admit that using the stark difference in keyword-count does serve as a proxy for language-complexity and by extension: a way to almost quantify good design. But using it as the basis for comparing languages today in 2021 is of limited-utility as the most relevant programming languages today1 are already either inspired by C or derived from it somehow, and they all share C's decision to do things in the library instead of the language, so all those languages similarly have a low keyword count compared to COBOL, SQL, and others, and so that's why C's keyword count just isn't interesting anymore.


1: C-inspired or C-derived languages in use today: C , Objective-C, Java, Groovy, Swift, C#, JavaScript, TypeScript, Go, PHP, Perl. Other popular languages that aren't modelled on C (like Haskell, OCaml, etc) do share C's library-first philosophy, but I can't say if C originated it or not - but I feel that languages opting for library-first designs is inevitable: the cost to implement language-features is easily ten-fold that of implementing library features.

  • Related