Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
C (programming language)
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== K&R C ===<!--[[K&R C]] redirects here--> [[File:The C Programming Language, First Edition Cover (2).svg|thumb|240x240px|The cover of the book ''The C Programming Language'', first edition, by [[Brian Kernighan]] and [[Dennis Ritchie]]]] In 1978 [[Brian Kernighan]] and [[Dennis Ritchie]] published the first edition of ''[[The C Programming Language]]''.<ref name="k&r1e">{{cite book |last1=Kernighan |first1=Brian W. |author-link1=Brian Kernighan |last2=Ritchie |first2=Dennis M. |author-link2=Dennis Ritchie | title=The C Programming Language | edition=1st |publisher=[[Prentice Hall]] |date=February 1978 |location=[[Englewood Cliffs, NJ]] |isbn=978-0-13-110163-0|title-link=The C Programming Language}}</ref> Known as ''K&R'' from the initials of its authors, the book served for many years as an informal [[Specification (technical standard)|specification]] of the language. The version of C that it describes is commonly referred to as "'''K&R C'''<!--boldface per WP:R#PLA-->". As this was released in 1978, it is now also referred to as ''C78''.<ref name="qOvzA">{{cite book |url=https://nxmnpg.lemoda.net/7/c78 |title=FreeBSD Miscellaneous Information Manual |date=May 30, 2011 |edition=FreeBSD 13.0 |chapter=C manual pages |access-date=January 15, 2021 |archive-url=https://web.archive.org/web/20210121024455/https://nxmnpg.lemoda.net/7/c78 |archive-date=January 21, 2021 |url-status=live}} [https://www.freebsd.org/cgi/man.cgi?query=c78&apropos=0&sektion=0&manpath=FreeBSD+9-current&arch=default&format=html] {{Webarchive|url=https://web.archive.org/web/20210121033654/https://www.freebsd.org/cgi/man.cgi?query=c78&apropos=0&sektion=0&manpath=FreeBSD+9-current&arch=default&format=html|date=January 21, 2021}}</ref> The second edition of the book<ref name="k&r2e">{{cite book |last1=Kernighan |first1=Brian W. |author-link1=Brian Kernighan |last2=Ritchie |first2=Dennis M. |author-link2=Dennis Ritchie |title=The C Programming Language | edition=2nd |publisher=[[Prentice Hall]] |date=March 1988 |location=[[Englewood Cliffs, NJ]] |isbn=978-0-13-110362-7|title-link=The C Programming Language |ref=none}}</ref> covers the later [[ANSI C]] standard, described below. ''K&R'' introduced several language features: * [[C file input/output|Standard I/O library]] * <code>[[long int]]</code> data type * <code>unsigned int</code> data type * Compound assignment operators of the form <code>=''op''</code> (such as <code>=-</code>) were changed to the form <code>''op''=</code> (that is, <code>-=</code>) to remove the semantic ambiguity created by constructs such as <code>i=-10</code>, which had been interpreted as <code>i =- 10</code> (decrement <code>i</code> by 10) instead of the possibly intended <code>i = -10</code> (let <code>i</code> be β10). Even after the publication of the 1989 ANSI standard, for many years K&R C was still considered the "[[Lowest common denominator (computers)|lowest common denominator]]" to which C programmers restricted themselves when maximum portability was desired, since many older compilers were still in use, and because carefully written K&R C code can be legal Standard C as well. In early versions of C, only functions that return types other than <code>int</code> must be declared if used before the function definition; functions used without prior declaration were presumed to return type <code>int</code>. For example: <syntaxhighlight lang="c"> long some_function(); /* This is a function declaration, so the compiler can know the name and return type of this function. */ /* int */ other_function(); /* Another function declaration. Because this is an early version of C, there is an implicit 'int' type here. A comment shows where the explicit 'int' type specifier would be required in later versions. */ /* int */ calling_function() /* This is a function definition, including the body of the code following in the { curly brackets }. Because no return type is specified, the function implicitly returns an 'int' in this early version of C. */ { long test1; register /* int */ test2; /* Again, note that 'int' is not required here. The 'int' type specifier */ /* in the comment would be required in later versions of C. */ /* The 'register' keyword indicates to the compiler that this variable should */ /* ideally be stored in a register as opposed to within the stack frame. */ test1 = some_function(); if (test1 > 1) test2 = 0; else test2 = other_function(); return test2; } </syntaxhighlight> The <code>int</code> type specifiers which are commented out could be omitted in K&R C, but are required in later standards. Since K&R function declarations did not include any information about function arguments, function parameter [[Type checking|type checks]] were not performed, although some compilers would issue a warning message if a local function was called with the wrong number of arguments, or if different calls to an external function used different numbers or types of arguments. Separate tools such as Unix's [[Lint programming tool|lint]] utility were developed that (among other things) could check for consistency of function use across multiple source files. In the years following the publication of K&R C, several features were added to the language, supported by compilers from AT&T (in particular [[Portable C Compiler|PCC]]<ref name="SkKfZ">{{cite report |first1=Bjarne |last1=Stroustrup |author-link=Bjarne Stroustrup |title=Sibling rivalry: C and C++ |publisher=AT&T Labs |number=TD-54MQZY |year=2002 |url=http://stroustrup.com/sibling_rivalry.pdf |access-date=April 14, 2014 |archive-date=August 24, 2014 |archive-url=https://web.archive.org/web/20140824072719/http://www.stroustrup.com/sibling_rivalry.pdf |url-status=live }}</ref>) and some other vendors. These included: * <code>[[void type|void]]</code> functions (i.e., functions with no return value) * functions returning <code>[[Struct (C programming language)|struct]]</code> or <code>[[Union (computer science)|union]]</code> types (previously only a single pointer, integer or float could be returned) * [[Assignment (computer science)|assignment]] for <code>struct</code> data types * [[enumerated type]]s (previously, preprocessor definitions for integer fixed values were used, e.g. <code>#define GREEN 3</code>) The large number of extensions and lack of agreement on a [[C standard library|standard library]], together with the language popularity and the fact that not even the Unix compilers precisely implemented the K&R specification, led to the necessity of standardization.<ref>{{Cite web |url=https://www.cs.man.ac.uk/~pjj/cs211/c_rationale/node2.html |title=Rationale for American National Standard for Information Systems β Programming Language β C |access-date=July 17, 2024 |archive-url=https://web.archive.org/web/20240717164722/https://www.cs.man.ac.uk/~pjj/cs211/c_rationale/node2.html |archive-date=July 17, 2024}}</ref>
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
C (programming language)
(section)
Add topic