Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 The C Language An International Standard CIS2450 Professional Aspect of Software Engineering.

Similar presentations


Presentation on theme: "1 The C Language An International Standard CIS2450 Professional Aspect of Software Engineering."— Presentation transcript:

1 1 The C Language An International Standard CIS2450 Professional Aspect of Software Engineering

2 2 ANSI C The C language appeared in the early 1970s and was originally cryptic, small, and tolerant. For the next ten years C evolved in the UNIX environment. The resultant language was first described in the paper “Portability of C Programs and the UNIX System,” by S.C. Johnson and Dennis Ritchie in This style of C was commonly called UNIX C.

3 3 ANSI C In 1989 the American National Standards Institute (ANSI) standardized C as standard X In December of that year the International Standards Organization ISO adopted the ANSI C standard making minor changes. In 1990 ANSI then re-adopted ISO standard C. This version of C is known as either ANSI C or Standard C.

4 4 Implementation Characteristics The ANSI standard defines several terms which describe the characteristics of an implementation. They are useful to describe what is and is not acceptable in the language. Implementation defined code means that the compiler writer chooses what happens and has to document it. –Example: whether the sign bit is propagated when shifting a bit right.

5 5 Implementation Characteristics Unspecified behavior for something correct which the standard does not impose any requirements. –Example: the order of argument evaluation. Undefined behavior is something incorrect which the standard does not impose any requirements. Anything may happen, from nothing, to a warning message, to program termination. –Example: what happens when a signed integer overflows.

6 6 Implementation Characteristics A constraint is a restriction or requirement which must be obeyed. If you do not then your program will become undefined. –Example: the operands of the % operator must be of integral type or a diagnostic will result. An interesting problem with the definition of constraints is that compilers only have to produce an error message if a program violates both syntax and constraints.

7 7 Implementation Characteristics Semantic rules which are not explicitly stated can be broken and because this behavior is undefined the compiler does not have to issue a warning. –Example: the C standard header files have a function called malloc, but redefining this function is not a constraint so the compiler does not have to warn if this happens.

8 8 Implementation Characteristics Strictly conforming code is one which: –uses only specified features –doesn't exceed any implementation-defined limit –has no output that depends on implementation defined, unspecified, or undefined features This is not a very interesting class because there are so few programs which meet the criteria.

9 9 Implementation Characteristics Conforming programs can depend on non- portable features. A conforming program is considered with respect to a specific implementation and may be non-conforming using a different compiler. It can have extensions, but not ones which alter the behavior of a strictly conforming program.

10 10 ANSI Changes to (older) C A variety of minimum sizes were defined by the standard including: –31 parameters in a function definition –31 arguments in a function call –509 characters in a source line –32 levels of nested parentheses in an expression –long ints are at least 32 bits

11 11 Differences between ANSI and K&R Prototype change –parameters must be written in the function declaration, not just the definition. Keyword changes –several new keywords were added including enum, const, volatile, signed, and void.

12 12 Differences between ANSI and K&R Quiet changes –which are mostly minor changes which cause code to still compile but perhaps operate in a different manner. Everything else –these changes will have almost no effect and will almost never be encountered in practice, e.g. trigraphs can be used to represent a single character by using three characters, so ??< represents {

13 13 New Features of C99 Coding –end-of-line (//) comments like C++ –Mix declarations and code –Remove implicit function declaration Data types –long long int (minimum 64bit Integer) –Variable length arrays –Flexible array members of structures Library –snprintf family of functions in stdio.h

14 14 Why Do We Care about Older C? For new development, we don’t, but… Huge installed code base is “old” –Many jobs involve maintenance of legacy code –Avoid misunderstanding legacy code Based on your new-C habits –Avoid introducing bugs into legacy code Keep to legacy coding style for consistency Choices: retain older C compiler or try to upgrade to new compiler standard (exposes “code rot”)

15 15 What is “code rot”? Aka “software rot” “bit rot” When program hasn’t been changed, yet stops working/compiling –Earlier assumptions no longer valid (e.g., famous Y2K bug → 2 bytes no longer enough) –Compiler, libraries, or operating system “upgraded,” features discontinued or incompatible

16 16 Holding Code Rot at Bay Recognize assumptions that won’t stand test of time –“Users will never need more than records, so 16- bit index is fine!” (+1 looks <0) → Comair fiasco Write strictly-conforming software, not relying on extensions or “tricks” –E.g., intentionally accessing outside array bounds Recompile when language spec revised, system upgraded, etc. –May discover small problems, easily fixed –Or BIG problems needing major reexamination


Download ppt "1 The C Language An International Standard CIS2450 Professional Aspect of Software Engineering."

Similar presentations


Ads by Google