music |
OSdata.com |
OSdata.com is used in more than 300 colleges and universities around the worldFind out how to get similar high web traffic and search engine placement. |
For information on how to interface high level languages and assembly languages, seeassembly/high level language interface
nature: systems langauge; procedural language
history: C was developed from 1969-1972 by Dennis Ritchie (with assistance by Brian W. Kernighan) of Bell Telephone Laboratories for use in systems programming for UNIX.
C is a computer programming language. It was developed out of the construction of the UNIX operating system. It has a modular programming structure and is thus useful in object oriented programming, as well as in developing graphical user interfaces. C++ is a superset of C. Other dialects include Small-C and Visual C. Language Finger, Maureen and Mike Mansfield Library, University of Montana.
Hello World example
#include <stdio.h>
main()
{
printf("Hello World\n");
}structure
format: free form
lexical elements
source code character set: A C compiler may use any character set that includes at least the following characters: the 52 upper case and lower case alphabetic characters ( A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z ), the 10 decimal digits ( 0 1 2 3 4 5 6 7 8 9 ), the blank or space character, and 29 designated graphic characters ( ! # % ^ & * ( ) - _ + = ~ [ ] \ | ; : ' " { } , . < > / ? ). Five formatting characters (backspace, horizontal tab, verticle tab, form feed, and carriage return) are often used in C (formatting characters are treated as spaces). The dollar sign ($) and the at sign (@) are also commonly used (but not required by the standard). Some form of line separator is required, but it doesnt have to be an actual character or character sequence.
execution character set: The execution character set for C is required to have the standard characters of the source code character set, plus a null character and a newline character. The null character must have the value 0 and is used to mark the end of strings. The newline character is used to divide character streams into lines during input or output. Run time libraries may convert between the newline character and some other character(s) (or lack of characters) during execution (such as compacting the carriage return/line feed combination into the newline character or generating the newline character at the end of a logical record or transforming between various record separators and the newline character).
white space: White space in C includes the blank (space character), horizontal tab, end-of-line, vertical tab, form feed, and comments. White space is ignored by the compiler (except when required to separate tokens or when used in a character or string constant), and therefore can be used freely by the programmer to make the program easy for a human to read. Some implementations of C treat nonstandard source characters as either white space or line breaks.
line termination: Each line in a C source program is terminated with an end-of-line character or character sequence. Optionally, certain formatting characters (such as carriage return, form feed or vertical tab) can also terminate lines. An empty line is a line that consists of only a terminating character or character sequence or white space and line termination. A logical source line can be continued past a line termination by using the backslash character (\) or the ANSI C trigraph ??/ immediately before the line termination. String constants and preprocessor command lines can cross line breaks through the use of logical source lines. In some implementations of C, tokens can also cross line breaks through the use of logical source lines.
line length: Many C compilers impose a maximum line length (both for physical source lines and for logical source lines). ANSI C requires logical source lines of at least 509 characters.
escape characters: The backslash character (\) is used as an escape character, allowing a programmer to include characters that would normally have a special meaning for the compiler.
alternative characters: ANSI C includes nine trigraphs (three character sequences) for encoding required characters outside of the ISO 646-1083 Invariant Code Set. These trigraphs always start with two consecutive question marks. These are:
trigraph normal ??( [ ??) ] ??< { ??> } ??/ \ ??! | ??' ^ ??- ~ ??= # multibyte characters: ANSI C supports both wide characters and multibyte characters.
Wide characters are binary characters that are more than one byte, typically used for expressing large alphabets.
Multibyte characters are the external representation of a wide character, in either the source or exeuction character set.
comments: Comments are started by the occurence of the two character sequence /* at any time other than within a character or string constant. Comments are terminated by the two character sequence */. ANSI C requires that comments be replaced with a single space character, but many C compilers remove comments without inserting a space character. Some non-UNIX C compilers allow nestable comments, which violates both original and ANSI C. To comment out large sections of a C program, use preprocessor commands:
#if 0
#endif
tokens
A C compiler always collects characters into the longest possible tokens, even if the result is not valid C. White space always divides tokens. White space can be used to prevent misinterpretation of C source code (for example,
x--y
would be tokenized as the illegalx -- y
[combining the two hyphens into a single token], whilex - -y
would be toeknized as the validx - - y
). White space must be used to separate an identifier, reserved word, integer constant, floating point constant from a following identifier, reserved word, integer constant, or floating point constant. Although ANSI C requires that comments be replaced by white space, many compilers dont, which can lead to unwanted token merging.operators: C has 15 simple operators ( ! % ^ & * - + = ~ | . < > / ? ), 11 compound assignment operators ( += -= *= /= %= <<= >>= &= ^= |= == ), and 10 other compound operators ( -> ++ -- << >> <= >= != && || ).
separators: C has 9 separator tokens ( ( ) [ ] { } , ; : ).
creating a program
The typical steps for compiling a program in C on a UNIX machine are:
step command input output create source code ed
emacs
use any text editortype from keyboard or terminal source code check
(for lexical errors)lint source code file listing with warnings preprocess cc
(or cpp)source code file c code file compile
(convert to assembly for specific hardware platform)cc2 c code file assembly source code file assemble
(for specific hardware platform)asm
(or as)
(or masm)assembly language file a.out
object code filelink link object code file executable code run program name file with
executable coderesults of program porting
www.digital.com/info/porting_assistant The Digital Porting Assistant (available for Digital UNIX 3.2, and shipped as part of the developer toolkit on Digital UNIX 4.0) is a graphical environment which aids in the porting process. In addition to doing lint-like checking of C and Fortran code, it also contains extensive on-line help regarding developing software on Digital UNIX.w55
further reading: books:
If you want your book reviewed, please send a copy to: Milo, POB 1361, Tustin, CA 92781, USA.
Price listings are for courtesy purposes only and may be changed by the referenced businesses at any time without notice.
C: A Reference Manual; 4th edition; by Samuel P. Harbison, Guy L. Steele; Prentice Hall Computer Books; December 1994; ISBN 0133262243; paperback; 455 pages; $34.36; REVIEW: I strongly recommend this book to working professionals. This is not a beginners book. Instead it a reference manual covering the details of the implementation of C on the entire range of platforms and compilers.
The C Programming Language, 2nd edition; by Brian W. Kernighan, Dennis M. Ritchie; Prentice Hall; June 1988; ISBN 0131103628; Paperback; 274 pages; $40.00; written by the creators of C; used by CS 308-273A (Principles of Assembly Languages) at McGill University School of Computer Science
Learn C on the MacIntosh; 2nd edition; by Dave Mark; Addison-Wesley Pub Co; October 1995; ISBN 0201484064; paperback (with CD-ROM); 474 pages; $27.96
A Book on C: Programming in C; 4th edition; by Al Kelley, Ira Pohl; Addison-Wesley Pub Co; January 1998; ISBN 0201183994; paperback; 726 pages; $39.95
Absolute Beginners Guide to C; 2nd edition; by Greg M. Perry; Sams; April 1994; ISBN 0672305100; paperback; $17.60
Codewarrior Software Development Using Powerplant; by Jan L. Harrington; AP Professional; May 1996; ISBN 0123264227; paperback (with CD-ROM); 295 pages; $24.47
C for Cobol Programmers: A Business Approach; by Jim Gearing; Carter Shanklin (Editor); Addison-Wesley Pub Co; August 1995; ISBN 0805316604; Paperback; $37.95
If you want your book reviewed, please send a copy to: Milo, POB 1361, Tustin, CA 92781, USA.
related software
Price listings are for courtesy purposes only and may be changed by the referenced businesses at any time without notice.
We are working on providing a second source.
Metrowerks CodeWarrior Discover Programming for Mac 5.0; C, C++, Java, and Pascal; PowerMac; $49.95
Metrowerks CodeWarrior Discover Programming for Windows 5.0; C, C++, Java, and Pascal; Windows 95, Windows 98, Windows NT; $49.95
Comptons Learning Programming Made Easy; The Learning Company; C, Java, TRUCK, and BASIC; Windows 95, Windows 98; $29.95
geek humor
C references are NULL && void* Warwick Allison
C: The language that combines the power of assembly language with the flexibility of assembly language.
C makes it easy to shoot yourself in the foot. C++ makes it harder, but when you do, it blows away your whole leg. Bjarne Stroustrup on C++
C is the Fortran of the 90s.
Wrong. C is the Fortran of the 70s. Norman DiamondC++ is to C, as lung cancer is to lung. Clayton Cramer
C is not a big language, and its not well served by a big book. Brian W. Kernighan and Dennis M. Ritchie, in The C Programming Language, Prentice Hall, 1988
OSdata.com is used in more than 300 colleges and universities around the world
Some or all of the material on this web page appears in the
free downloadable college text book on computer programming.
Tweets by @osdata A web site on dozens of operating systems simply cant be maintained by one person. This is a cooperative effort. If you spot an error in fact, grammar, syntax, or spelling, or a broken link, or have additional information, commentary, or constructive criticism, please e-mail Milo. If you have any extra copies of docs, manuals, or other materials that can assist in accuracy and completeness, please send them to Milo, PO Box 1361, Tustin, CA, USA, 92781.
Click here for our privacy policy.
previous page next page home page
one level up
peer level
This web site handcrafted on Macintosh computers using Tom Benders Tex-Edit Plus and served using FreeBSD .
Names and logos of various OSs are trademarks of their respective owners.
Copyright © 1998, 2000, 2001, 2004, 2007 Milo
Last Updated: October 15, 2007
Created: August 25, 1998
previous page next page