C standard library - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

C standard library

Description:

The result was a reference manual with approximately 750 pages, ... cabriolet * p = dynamic_cast cabriolet* (cp); Initialization of const static members ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 24
Provided by: sfu5
Category:

less

Transcript and Presenter's Notes

Title: C standard library


1
C standard library
2
History
  • Standardization of c started in 1989 and
    finished at the end of 1997.
  • The result was a reference manual with
    approximately 750 pages, published by ISO.
  • The standard has the title
  • Information technology programming languages
    C

3
Standard is an important milestone
  • 1- it defines the exact content and behavior of
    C
  • 2- it makes it easier to teach C
  • 3- to use C in applications
  • 4- port C programs to different platforms

4
New language features
  • C is not the same as 5 years ago
  • All compilers are not able to provide all
    features.

5
Templates
  • Almost all parts of the STL are written as
    templates
  • Templates are functions or classes written for
    one or more types not yet specified.
  • Keyword typename

6
  • template classltTgt
  • inline const T max (const T a, const T
    b)
  • return a lt b ? b a
  • template ltclass Tgt
  • class myClass
  • typename TsubType ptr
  • myClassltintgt x1

7
Explicit initialization for fundamental types
  • int i1 //undefined value
  • int i2 int() //initialized with zero

8
Exception handling
  • Handling exceptions without polluting your
    function interface
  • If you encounter an unexpected situation , you
    can stop the usual data processing by throwing an
    exception
  • The throw statement starts a process called stack
    unwinding.

9
namespaces
  • As I completely discussed first session

10
Type bool
11
Keyword explicit
  • class Stack
  • explicit Stack (int size)
  • .
  • Stack s
  • s 40

12
New operators for type conversion
  • static_cast
  • float x
  • cout ltlt static_castltintgtx
  • dynamic_cast
  • Allows to downcast a polymorphic type to its real
    static type . This is the only cast that is
    checked at runtime.
  • const_cast
  • Adds or removes the constness of an operator
  • reinterpret_cast

13
  • class car
  • class cabriolet public car
  • ..
  • car cp
  • cabriolet p dynamic_castltcabrioletgt(cp)

14
Initialization of const static members
  • class myClass
  • static const int num 100
  • int elements num // OK
  • ..

15
Definition of main
  • There are only two correct and portable versions
    of main( )
  • int main( )
  • int main (int argc, char argv)

16
General concepts
  • The namespace std
  • The names and formats of header files
  • The general concepts of errors and exception
    handling
  • A brief introduction to allocators

17
Namespace std
  • The use of std for all identifiers of the C
    standard library was introduced during the
    standardization
  • But in old header files identifiers are defined
    in global scope

18
Header files
  • Old extensions .h .hpp .hxx
  • New no extension
  • Inside new headers all identifiers inside
    namespace std
  • C derived headers added c at the beginning of
    their name

19
Error exception handling
  • Every part of standard library has its own
    exceptions like STL , String
  • All exceptions thrown from the language or the
    library are derived from the class exception
  • The standard exception classes can be divided
    into 3 groups
  • 1- exceptions for language support
  • 2- exceptions for the C standard library
  • 3- exceptions for errors outside the scope of a
    program

20
(No Transcript)
21
More about exceptions
  • We can throw standard exceptions
  • We derive standard exception classes
  • class myProblem public stdexception
  • ..
  • String s
  • .
  • throw out_of_range(s)

22
Allocators
  • The C standard library uses in several places
    special objects to handle the allocation and
    deallocation of memory.
  • Such objects are called allocators.

23
AYLOOZ
  • Alireza Fathi
Write a Comment
User Comments (0)
About PowerShow.com