C Programming Language

This page is for students enrolled in the Fall 2009 C/C++/OO/Visual Studio Raytheon in-house course.

Image2 Course Info

Image2 Course Outline

Image2 Links 

Image2 Instructor 

Image2 Prerequisites

Image2 C programming terminology

Goals:

To refresh our understanding of and to relearn the C Programming Language. This class is offered in preparation for the Lab Windows/CVI class that will be offered later this fall.

Class Schedule:

Eight one-hour meetings, Wednesdays at noon  starting 30 September 2009. Building B1, Room S827. (Computer training room on North side of the building). Each hour attended counts towards training time. Roll is taken (via a sign-in sheet) at every class, and your attendance is recorded in the training database. We may go an extra session or two as desired by the class (and the instructor).

Text:

  C: A Reference Manual, Harbison & Steele, Prentice Hall, Paperback, 5th edition, Published 2002, 533 pages, ISBN 0-13-089592X. Note that there are several errata in the 1st and 2nd printings, some of which are "severe". See links below for errata listing.

A CD will also be available with various presentations, white papers, etc. You should also expect to use the Web, see the links section below.

There are countless books on the C Programming Language, available at any bookstore with a computer section. The class text is the best I've found for use as a reference while writing C programs. It's sometimes referred to as "H & S". If you don't know C at all, I wouldn't try to learn it from this particular book - I'd use the 2nd edition of Kernighan and Ritchie (K & R).

Instructor:

Robert G. (Bob) Hayes, Senior Principal Software Engineer, Raytheon Vision Systems. Bob has been designing software systems at Hughes Aircraft/Raytheon for nearly 30 years. He holds a BSE in Electrical Engineering and an MS in Computer Science. He has extensive experience with the C Programming Language.

Prerequisites:

The student should have some familiarity with C. This class is generally too short to learn C from scratch, though an adept student may in fact do so.

Other:

The only way to really learn/understand a programming language is to write code. Expect to do exercises in class and on your own. There will be a C compiler installed at each computer workstation in the training room. Each workstation must be shared between two students - working together on exercises in class is allowed and expected. A free Borland C/C++ command line compiler is available for home use - see links below. RVS is site-licensed for Microsoft Visual Studio - which includes a C/C++ compiler. Other Goleta sites may have a different licensing arrangement.

Links:

Here are some useful links. There is an immense amount of useful information on C available on the web.

http://www.careferencemanual.com/ Home page for the text, includes errata for first and second printings.

http://www.eskimo.com/~scs/C-faq/faq.html Frequently asked questions about C.

http://www.lysator.liu.se/c/  A C portal.

http://cplus.about.com/library/blctut.htm A C tutorial.

http://www.borland.com/bcppbuilder/freecompiler  What it sounds like.

http://cm.bell-labs.com/cm/cs/who/dmr/chist.html History of C from the guy who made it.

http://www.csd.uwo.ca/~jamie/C/ C programming resources.

http://www.lysator.liu.se/c/ten-commandments.html 10 commandments of C programming.

http://www0.us.ioccc.org/main.html Obfuscated C contest.

http://www.eskimo.com/%7escs/cclass/krnotes/top.html C programming notes for K&R book.

http://users.powernet.co.uk/eton/kandr2/ Answers to the exercises in the K&R book.

http://cprogramminglanguage.net/ A website dedicated to C language.

http://www.di-mgt.com.au/cprog.html  Nice page on C, in particular Win32 programming and C.

http://www.dmoz.org/Computers/Programming/Languages/C/FAQs,_Help,_and_Tutorials/   Another C portal.

http://www.iu.hio.no/~mark/CTutorial/CTutorial.html   An extensive C tutorial.

http://www.youtube.com/watch?v=b00HsZvg-V0&feature=SeriesPlayList&p=78280D6BE6F05D34   Good grief, a C tutorial on You Tube!

http://david.tribble.com/text/cdiffs.htm   Differences between C, C++, C89, C99

http://www.cs.lmu.edu/~ray/notes/c/     Intro to C by Ray Toal, a well liked professor of Computer Science at LMU.

http://msdn.microsoft.com/en-us/library/fw5abdx6.aspx  What Microsoft has to say about C and Visual Studio.

http://www.campwoodsw.com/   You can find the SourceMonitor tool here.

http://www.coverity.com/    Static analysis tool vendor’s site.

http://www.klocwork.com/ Another static analysis tool vendor’s site.

http://www.ibm.com/developerworks/aix/library/au-hook_duttaC.html    An IBM C programming style guide.

http://home.att.net/~jackklein/ctips01.html    Another style guide, this one from AT&T.

http://www.chris-lott.org/resources/cstyle/   This page has links to many more style guides.

 

 

Back to top

  

Course Outline:

We'll simply follow the course text from the beginning to as far as we get. We may also spend more time on selected topics if there's particular interest. There's an outline of the book on the book's website.

 

Back to top

 

C Programming Terminology

See how many of these you can define.

Scope

Visibility

Extent

Structure

Expression

Union

Data type

Typedef

Block

Block structured language

Imperative language

Long

Short

Float

Double

Unsigned

Type conversion

Function

Macro

Preprocessor

Heap

Stack

Operator

Unary operator

Binary operator

Pragma

Static

Automatic

Char

Malloc()

Calloc()

Standard library

Module

Translation unit

Parameter

Golden rule of parameterization

Pass by value

Pass by reference

Pointer

Void

Postfix operator

Prefix operator

Cast

Type conversion

Return value

Lexical scope

Block scope

Free()

Format descriptor

Printf()

Getchar()

Token

Syntax

Semantics

Initializer

Lexical element

Continue

Switch

Break

Goto

Statement label

Constant

Separator

Statement

Lvalue

Precedence

Conditional expression

Assignment

Order of evaluation

Formal parameter

Main()

Inline function

Wide character

string

Array

Zero-based

Enumeration type

Signal

Exit()

Abort()

Byte ordering

Big-Endian

Little-Endian

Packing

Literals

Names

Subscript

Component selection

Reference

Dereference

Bitwise negation

Equality operator

Compound assignment

C++ compatibility

Prototype

Header file

Storage class specifier

Implicit declaration

Side effect

Comment

Character repertoire

Identifier

Keyword

ASCII

ISO

Whitespace

Clean C

Standard C

Traditional C

C99

C95

C89

Trigraph

Terminal symbol

Unix

EBCDIC

Indirect addressing

Module scope

External function

External variable

Global

Recursion

Quicksort

Scanf()

Element

ANSI

Floating point

 

 

Back to top

Homework exercises

  Try doing one or more of these problems:

1. Edit the following obfuscated code contest winner to have a consistent, “good” style, with comments explaining what the code does. If need be, alter it to get an error and warning free compile on your C compiler.
main(O){int I,Q,l=O;if(I=l*4){l=6;if(l>5)l+=Q-8?l-(Q=getchar()-2)%2:l;if(Q*=2)O+="has dirtiest IF"[(I/-Q&12)-l/Q%4];}printf("%d\n",8+O%4);}
2. Write a C program that can be run as a “filter” from a Windows Command Shell prompt (i.e a “DOS command line”) that removes all of the comments from a C program. C comments do not nest, and consider only the K&R (C89) form   /* … */. Remember that you can have string constants that include the character sequences /* and */ and that these are not comments. You can ignore special cases, such as trigraphs, line continuation with \, or <> quoting on #include. A filter accepts input from the standard input device and outputs data to the standard output device, and can be redirected or piped. This is K&R exercise 1-23. Annotate your code and use a clean, consistent style. Check your answer by running the filter on its own source code.

3. Write a C program that uses the qsort (quick sort) C standard library function to sort an array of signed integers. Do another that sorts an array of doubles, and yet another to sort an array of structs. Can you write a single program that can sort either array type given just the array name?

4. Write a C program that performs a cocktail sort on an array of floats, and another that does a shell sort. See if you can “instrument” the code to measure how long each sort takes on a given array of floats.  Hint … look in the C standard library for time functions, or see if you can figure out how to use the performance counters in the Pentium chip to do the measurement.

5. Write a C program that can be run as a “filter” from a Windows Command Shell prompt (i.e a “DOS command line”) that removes all of the comments from a C program. C comments do not nest, and consider only the K&R (C89) form   /* … */. Remember that you can have string constants that include the character sequences /* and */ and that these are not comments. You can ignore special cases, such as trigraphs, line continuation with \, or <> quoting on #include. A filter accepts input from the standard input device and outputs data to the standard output device, and can be redirected or piped. This is K&R exercise 1-23. Annotate your code and use a clean, consistent style. Check your answer by running the filter on its own source code.

6. Write a short and accurate explanation of the following statements about C:

1. All parameters are passed by value in C, but that value can be a pointer.

2. All arrays in C are singly dimensioned.

3. Use of an array subscript is the same as deferencing the array name.

4. C arrays are stored in row-major order.

5. Although C functions use pass-by-value semantics, arrays are in effect passed by reference.

6. A function declaration    func ()   is not the same as   func (void).

7. Many operations possible in C have undefined behavior.

8. C has a static, weak, type system.

Back to top

Last Revised: 23 October 2009
Copyright
Ó 2004-2009 Robert G. Hayes.
e-mail the webmaster: r*g*hayes@earthlink.net (remove the *'s)

 

Best viewed at 1024x768 16 bit color!
I'm not responsible for your poor resolution!
Pump it up!