0

Recently I've read "Extreme C Programming" book and often heard that

C is a Standard

I know, C is standardized by ANSI. But what does it really mean? Is this is about keywords, supported functions or headers?

Lundin
  • 195,001
  • 40
  • 254
  • 396
Ash Blade
  • 11
  • 1
  • 3
  • 1
    Yes, there is a standard that describes the behavior of the language [C Standard (latest draft)](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2596.pdf) and there is a convenient [C11 Standard - in html](http://port70.net/~nsz/c/c11/n1570.html) that you can reference as well. – David C. Rankin Jun 20 '22 at 06:37
  • Another way to look at "Why is it called Standard?" is programs written that conform to the standard are guaranteed to behave in a defined manner. It provides a basic guarantee -- follow the standard and your program will have defined behavior. If you write code that does not conform to the standard, then all bets are off and the behavior of your program will be undefined, or implementation defined. – David C. Rankin Jun 20 '22 at 06:45
  • See: [Undefined, unspecified and implementation-defined behavior](https://stackoverflow.com/q/2397984/3422102) and [What is indeterminate behavior in C++ ? How is it different from undefined behavior?](https://stackoverflow.com/q/11240484/3422102) and [Undefined behavior](https://en.cppreference.com/w/c/language/behavior) – David C. Rankin Jun 20 '22 at 06:46
  • 1
    Aside for published 'standards', C has been around for so long and is available for just about all hardware platforms, that it could be said to be a common feature. Without more context on the specific quote, its hard to tell quite what they are referring too. The capitalisation of 'S' in "C is a Standard" seems questionable. – Dave Meehan Jun 20 '22 at 08:02

3 Answers3

3

It means that there is international standardization in the form of a document ISO/IEC 9899:2018 1) stating how compilers and applications should behave. ISO is an international collaboration, consisting of working groups that take input from national standardization institutes such as ANSI/INCITS in USA. So saying that C is standardized by ANSI is wrong unless you happen to live in USA, where the local name for the standard is INCITS/ISO/IEC 9899:2018.

The whole language is specified in this document: terms, behavior, keywords, operators, environment considerations, certain libraries and so on.


1) The official standard costs money to obtain. For student/hobbyist purposes, you can download a draft version of the standard for free though, such as the C11 draft.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Without the context we don't know whether it means "C is a standard" for programming in the sense of "Blender is a standard" for 3D rendering. After all, that's what C was created for, including its *Standard* Library. – Peter - Reinstate Monica Jun 20 '22 at 08:43
  • @Peter-ReinstateMonica We do know since a formal standard exists, not to be confused with informal "de facto" standards. The C standard includes a formal specification of the standard library. – Lundin Jun 20 '22 at 08:56
  • I can assure you that *we* don't know, because *I* don't know. ;-) – Peter - Reinstate Monica Jun 20 '22 at 09:11
  • Maybe I'm assuming that people who write answers here share some common knowledge about the world so that one doesn't have to spell everything out to them. (Do I sound offended? ;-) ) – Peter - Reinstate Monica Jun 20 '22 at 10:49
  • @Peter-ReinstateMonica Ok so how do we know that the OP is asking about programming, since C is clearly a letter, the third one in the Latin alphabet and this is the "standard" meaning of C in a non-engineering context. – Lundin Jun 20 '22 at 10:52
0

I know, C is standardized by ANSI

C was standardized by ANSI in 1989 (aka C89).

It was then globally adopted by ISO/IEC JTC1/SC22 Programming Languages in 1990 as ISO/IEC 9899:1990 (aka C90).

Working Group 14 (WG14) of SC22 have subsequently evolved the C Standard as:

  • ISO/IEC 9899:1990 (aka C90)
  • ISO/IEC 9899:1990/AMD1:1995 (aka C95)
  • ISO/IEC 9899:1999 (aka C99)
  • ISO/IEC 9899:2011 (aka C11)
  • ISO/IEC 9899:2018 (aka C18 - although sometimes called C17 as __STDC__ is 201710L)
  • ISO/IEC 9899:202x (aka C2x) is pending...

There were a couple of TCs too...

As a Standard it has requirements for conformance.

Andrew
  • 2,046
  • 1
  • 24
  • 37
  • "STDC is 200712" is a typo, isn't it? The define should start with 2017... or 2018... . [Here](https://sourceforge.net/p/predef/wiki/Standards/) they claim `__STDC_VERSION__ = 201710L`. – Peter - Reinstate Monica Jun 20 '22 at 08:41
  • More detailed info can be found [here](https://stackoverflow.com/a/17209532/584518). It is `201710L` for C17 indeed. – Lundin Jun 20 '22 at 08:58
  • Thanks Peter - fixed... and thanks to Eric for fixing the broken markup too – Andrew Jun 20 '22 at 12:07
0

If the sentence indeed refers to C being ANSI/ISO standardized, it refers to a lot of things, including your "keywords, supported functions or headers". The ISO C standard defines:

  • The preprocessor directives (defines and includes).
  • The syntax (the grammar, the formal structure): The keywords and other building blocks of the language (literals, operators, identifier syntax) and how these can be combined to expressions and statements in order to form a syntactically correct C program.
  • The semantics of a program (which grammatically correct constructs are allowed, and what is their meaning).
  • The C Standard Library (malloc, printf, memcpy etc.). The "user facing" part of that library are the headers (stdio.h, string.h etc.) which name and describe the functions available in the standard library. The "system facing" part of the standard library is the actual compiled code of those functions, typically in the form of library files in a platform specific format with platform specific names in platform specific locations such as libc.a on a gcc/linux system. Because the standard library is so commonly used by normal programs, no special effort must be made to link to it: The linker does that automatically. (You still need to include the proper header file though to let the compiler know about the function names and the arguments you want to use.)

Saying that C is a "standard" can have both meanings: The ISO standardization detailed above, but also the fact that C, compared to assembler, is an abstraction layer that shields a program from peculiarities of the underlying hardware, for example is word length, its endianness, signedness of its character type etc. The interaction with the "system" a program is running on is abstracted through the aptly named "Standard Library".

A well-written C program runs without or with only minor modification on a wide variety of platforms. In this sense C was a de-facto "standard" for programming for years before its formal ISO standardization at the end of the 1980s, much in the sense that *nix in one of its flavors has become a de-facto standard for server operating systems.

Addendum: After browsing the accessible part of the book that inspired your question I can say with confidence that the author indeed addresses both meanings of "standard": He talks about the different ISO C standard versions, dedicating an entire chapter to C 2018; but he also says the following, on "54% of sample" (I cannot see a page number there; emphasis by me):

The size of a pointer depends on the architecture rather than being a specific C concept. C doesn't worry too much about such hardware-related details, and it tries to provide a generic way of working with pointers and other programming concepts. That is why we know C as a standard.

Peter - Reinstate Monica
  • 15,048
  • 4
  • 37
  • 62
  • Except prior to C90 there were different versions and flavours too. It ain't a standard if everyone is making their own version of it. – Lundin Jun 20 '22 at 09:02
  • @Lundin, the library was named "Standard Library" for a reason when ISO standardization was not even on the horizon. Natural language is often ambivalent and context dependent, as much as you may despise and deny it. – Peter - Reinstate Monica Jun 20 '22 at 09:14
  • But standard means one unique set of functionality, not multiple diverse ones. Take for example the SPI bus commonly used in embedded systems. It is not formally standardized, so every integrated circuit claims they have "SPI", but once you start digging deeper you find that they may have weird timing requirements unique to that particular part, incompatible with everything else. It's not even a de facto standard since everyone implements it slightly differently. Same with the so-called "standard library" - which functions that were included in it was just arbitrary from compiler to compiler. – Lundin Jun 20 '22 at 09:24
  • @Lundin By your definition C is clearly not a standard at all. (Either one of C90, C99, C11 and C18 is though.) I still think you under-appreciate the fuzziness of reality and natural language. – Peter - Reinstate Monica Jun 20 '22 at 09:30
  • That's just silly. Each revision is explicitly flagged as obsolete and withdrawn once a newer version becomes available. ISO will even refuse to provide older versions. – Lundin Jun 20 '22 at 09:42
  • @Lundin [Ah, silly, eh ;-)?](https://gcc.gnu.org/onlinedocs/gcc/Standards.html) – Peter - Reinstate Monica Jun 20 '22 at 10:52