C Programming Language CIS 218 Description C is a procedural - - PowerPoint PPT Presentation

c programming language
SMART_READER_LITE
LIVE PREVIEW

C Programming Language CIS 218 Description C is a procedural - - PowerPoint PPT Presentation

C Programming Language CIS 218 Description C is a procedural languages designed to provide lowlevel access to computer system resources, provide language constructs that map efficiently to machine instructions, and require minimal


slide-1
SLIDE 1

“C” Programming Language

CIS 218

slide-2
SLIDE 2

Description

  • C is a procedural languages designed to provide lowlevel access to computer system

resources, provide language constructs that map efficiently to machine instructions, and require minimal run-time support. C is useful for applications previously would have been coded in assembly language.

  • C language was designed to encourage machine-independent programming (i.e.

source code portable) for a very wide variety of computer platforms and operating systems if written in standards-compliant syntax

  • Some early C compilers were implemented on PDP-11 processors having only 16

address bits. C compilers for several common 8-bit platforms have been implemented as well.

slide-3
SLIDE 3

History

  • The initial development of C occurred at AT&T Bell Labs between 1969 and 1973. It

was named "C" because many of its features were derived from an earlier language called "B" by Ken Thompson.

  • The Unix operating system, originally implemented in assembly language on a DEC

PDP-7 by Dennis Ritchie and Ken Thompson. They later decided to port the

  • perating system to a DEC PDP-11. The original PDP-11 version of the Unix system

was developed in assembly language.

  • B's lack of functionality to take advantage of some of the PDP-11's features, notably

byte addressability, led to the development of an early version of the C programming

  • language. By 1973, the C language had become powerful enough that most of the

Unix kernel was rewritten in C. This was one of the first operating system kernels implemented in a language other than assembly.

  • In 1978, Brian Kernighan and Dennis Ritchie published the first edition of The C

Programming Language. The second edition of the book covers the later ANSI C standard.

slide-4
SLIDE 4

ANSI C and ISO C

  • In 1983, the American National Standards Institute (ANSI) formed a committee,

X3J11, to establish a standard specification of C. In 1989, the standard was ratified as ANSI X3.159-1989 "Programming Language C." with features such as data declarations, memory allocation., various data structures and enumeration types. This version of the language is often referred to as ANSI C, Standard C, or sometimes C89.

  • In 1990, the ANSI C standard (with formatting changes) was adopted by the

International Organization for Standardization (ISO) as ISO/IEC 9899:1990, which is sometimes called C90. Therefore, the terms "C89" and "C90" refer to the same programming language. The standards committee included several additional features in "C90) borrowed from C++ (Microsoft version).

  • ANSI no longer develops the C standard independently, but defers to the ISO C

standard.

  • Current common C compilers and most portable C code being written nowadays is

based on "C89". Any program written in Standard C without hardware-dependent instructions will run correctly on any platform with a conforming C implementation, within its system architecture limits.

slide-5
SLIDE 5

Syntax

  • C source code is free-form allowing arbitrary use of whitespace to format code.

Comments appear either between the delimiters /* and */, or in later versions following // until the end of the line.

  • C programming language syntax is similar to that specified in the C shell language

from which the shell was derived.

  • Every set of "logic" in C is formatted as a function; using the basic bash function

syntax; even the main program

  • Each source file contains variable declarations using keywords such as struct, union,

and enum. usually by writing the type followed by the variable name.

  • Function definitions, contain declarations and expression statements consisting of an

expression to be evaluated, followed by a semicolon; Expressions can use a variety

  • f built-in operators and may contain function calls.
  • Keywords such as char and int specify built-in types. Sections of code are enclosed in

braces ({ and }, sometimes called "curly brackets") to limit the scope of declarations and to act as a single statement for control structures.

  • To modify the normal sequential execution of statements, C provides several control-

flow statements identified by reserved keywords. if-then, while, until, case.

slide-6
SLIDE 6

"Hello, world" example

  • The "hello, world" example has become the standard example for introductory

programming languages. The program prints "hello, world" to the standard output (STDOUT).

  • The C89 standard-conforming "hello, world" program is:

#include <stdio.h> int main(void) { printf("hello, world\n"); return 0; }

  • The first line of the program contains a preprocessing directive, indicated by #include.

This causes the preprocessor — the first tool to examine source code as it is compiled — to substitute the line with the entire text of the stdio.h standard header, which contains declarations for standard input and output functions such as printf.

  • The angle brackets surrounding stdio.h indicate that stdio.h is located using a search

strategy that prefers standard headers to other headers having the same name. Double quotes may also be used to include local or project-specific header files.

slide-7
SLIDE 7

"Hello, world" example (Cont.)

  • The next line is the function main. The run-time environment calls the main function

to begin program execution. The type specifier int indicates that the return value returned to the invoker (run-time environment), is an integer. The keyword void as a parameter list indicates that the main function takes no arguments.

  • The opening curly brace indicates the beginning of the definition of the main function.
  • The next line calls a function named printf (as declared in stdio.h) supplied from a

system library. The printf function is passed a single argument, the address of the first character in the string literal "hello, world\n" ending with the \n escape sequence that C translates to a newline character.

  • The semicolon; terminates the statement.
  • The return statement terminates the execution of the main function and causes it to

return the integer value 0, which is interpreted by the run-time system as an exit code indicating successful execution.

  • The closing curly brace indicates the end of the code for the main function.
slide-8
SLIDE 8

Libraries

  • The C programming language uses libraries as a set of functions contained within a

single "archive" file. Each library typically has a header file, prototypes of the functions contained within the library, and declarations of special data types and macro symbols used with these functions.

  • In order for a program to use a library, it must include the library's header file. The

library must be linked with the program, which in many cases requires compiler flags.

  • The most common C library is the C standard library, which is specified by the ISO

and ANSI C standards and comes with every C implementation. This library supports stream input and output, memory allocation, mathematics, character strings, and time

  • values. Other common C library functions are those used by applications specifically

targeted for Unix and Unix-like systems with functions that provide an interface to the kernel.

  • Since many programs have been written in C, there are a wide variety of other

libraries available. Libraries are often written in C because C compilers generate efficient object code; programmers then create interfaces to the library so that the routines can be used from higher-level languages like Java, Perl, and Python.

slide-9
SLIDE 9

Related languages

  • C syntax is the basis for many later languages such as Java, C#, Perl, PHP,

JavaScript, LPC, and Unix's C Shell. In fact, C compilers are so efficient, most of these languages are written in C.

  • Perl is an example of a popular programming language rooted in C. Perl's syntax

closely follows C syntax. The standard Perl implementation is written in C and supports extensions written in C.

  • Object-oriented languages C++ and Objective-C are two different extensions of C

that provided object-oriented capabilities.

  • C++ adds greater typing strength, scoping and other tools useful in object-oriented

programming and permits generic programming via templates. Nearly a superset of C, C++ now supports most of C, with a few exceptions

  • Objective-C remains a strict superset of, C that permits object-oriented programming

using a dynamic/static typing model. Objective-C derives its syntax from both C and Smalltalk

  • Because of their object orientation C++ (later C Sharp and C.NET in Microsoft) are

common languages used for graphical user interfaces (i.e. Windows).

slide-10
SLIDE 10

Development environments

  • Many tools have been created to assist C programming such as automated source

code checking, auditing, source code versioning, project development and packaging, program debugging. The text covers the basic tools for C program development under UNIX.

  • There are also compilers, libraries and operating system level options for performing

array bounds checking, buffer overflow detection, serialization, automatic garbage collection and code optimization that are not a part of Standard C.

  • Language specific development environments called Integrated Development

Environments (IDEs) provide GUI code development user interfaces, automatically perform code versioning, program linking and packaging and redistribution

  • mechanisms. These IDE’s tend to be vendor specific (Microsoft, Borland). And are

usually used for platform specific (i.e. non-portable) code development.