Part I Part 1 – Brief Overview of C89 Vs C99 Vs

Part I Part 1 – Brief Overview of C89 Vs C99 Vs

C89 vs C99 C11 Overview of the Lecture Introduction to Object Oriented Part 1 – Brief Overview of C89 vs C99 vs C11 Programming in C++ C89 vs C99 Part I C11 K. N. King: Appendix B Jan Faigl Part 2 – Object Oriented Programming (in C++) Part 1 – Brief Overview of C89 vs C99 vs Department of Computer Science Differences between C and C++ C11 Faculty of Electrical Engineering Czech Technical University in Prague Classes and Objects Lecture 10 Constructor/Destructor BE5B99CPL – C Programming Language Example – Class Matrix Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 1 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 2 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 3 / 49 C89 vs C99 C11 C89 vs C99 C11 C89 vs C99 C11 Differences between C89 and C99 Differences between C89 and C99 Differences between C89 and C99 – Additional Libraries Bool type – C99 provides _Bool type and macros in stdbool.h Comments – In C99 we can use a line comment that begins with // Loops – C99 allows to declare control variable(s) in the first <stdbool.h> – macros false and true that denote the logical Identifiers – C89 requires compilers to remember the first 31 values 0 and 1, respectively characters vs. 63 characters in C99 statement of the for loop Only the first 6 characters of names with external linkage are Arrays – C99 has <stdint.h> – integer types with specified widths significant in C89 (no case sensitive) designated initializers and also allows <inttypes.h> – macros for input/output of types specified in In C99, it is the first 31 characters and case of letters matters to use variable-length arrays <stdint.h> Keywords – 5 new keywords in C99: inline, restrict, _Bool, Functions – one of the directly visible changes is <complex.h> – functions to perform mathematical operations on _Complex, and _Imaginary In C89, declarations must precede statements within a block. In complex numbers C99, it cam be mixed. Expressions <tgmath.h> – type-generic macros for easier call of functions Preprocessor – e.g., In C89, the results of / and % operators for a negative operand can defined in <math.h> and <complex.h> be rounded either up or down. The sign of i % j for negative i or j C99 allows macros with a variable number of arguments depends on the implementation. C99 introduces __func__ macro which behaves as a string variable <fenv.h> – provides access to floating-point status flags and In C99, the result is always truncated toward zero and the sign of that stores the name of the currently executing function control modes i i % j is the sign of . Input/Output – conversion specification for the *printf() and Further changes, e.g., see K. N. King: Appendix B *scanf() functions has been significantly changed in C99. Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 5 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 6 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 7 / 49 C89 vs C99 C11 C89 vs C99 C11 C89 vs C99 C11 Overview of Changes in C11 – 1/2 Overview of Changes in C11 – 2/2 Generic Selection In C11, we can use a generic macros, i.e., macros with results that can be computed according to type of the pass variable (expression) Unicode support – <uchar.h> Memory Alignment Control – _Alignas, _Alignof, and double f_i(int i) Bounds-checking functions – e.g., strcat_s() and strncpy_s() int main(void) aligned_alloc, <stdalign.h> { { gets() for reading a while line from the standard input has been return i + 1.0; int i = 10; Type-generic macros – _Generic keyword } double d = 10.0; removed. double f_d(double d) printf("i=%d;d=%f\n", i, d); _Noreturn keyword as the function specifier to declare function It has been replaced by a safer version called gets_s() { return d - 1.0; printf("Results of fce(i)%f\n", does not return by executing return statement (but, e.g., rather In general, the bound-checking function aim to that the software written } fce(i)); in C11 can be more robust against security loopholes and malware attacks. printf("Results of fce(d)%f\n", longjmp)– <stdnoreturn.h> #define fce(X) _Generic((X),\ fopen() interface has been extended for exclusive fce(d)); <threads.h> – multithreading support int: f_i,\ return EXIT_SUCCESS; create-and-open mode ("..x") that behaves as O_CREAT|O_EXCL double: f_d\ } <stdatomic.h> – facilities for uninterruptible objects access in POSIX used for lock files )(X) lec10/demo-matrix.cc wx – create file for writing with exclusive access clang -std=c11 generic.c -o generic && ./generic Anonymous structs and unions, e.g., for nesting union as a i = 10; d = 10.000000 member of a struct w+x – create file for update with exclusive access Results of fce(i) 11.000000 Safer fopen_s() function has been also introduced Results of fce(d) 9.000000 A function is selected according to the type of variable during compilation. Static (parametric/compile-time) polymorphism Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 9 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 10 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 11 / 49 Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix C C++ C C++ C was developed by Dennis Developed by Bjarne Stroustrup Concept of virtual functions is C++ offers the facility of using Ritchie (1969–1973) at AT&T in 1979 with C++’s predecessor “C not present in C virtual functions Part II Bell Labs with Classes” No operator overloading C++ allows operator overloading C is a procedural (aka C++ is procedural but also an Data can be easily accessed by Data can be put inside objects, Part 2 – Introduction to Object Oriented structural) programming object oriented programming other external functions which provides better data security language language C is a middle level language C++ is a high level language Programming C is a subset of C++ C++ can run most of C code The solution is achieved through C++ can model the whole solution C programs are divided into C++ programs are divided into a sequence of procedures or in terms of objects and that can modules and procedures classes and functions steps make the solution better organized C is a function driven C++ is an object driven language C programs use top-down C++ programs use bottom-up language approach approach Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 12 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 14 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 15 / 49 Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix C C++ Objects Oriented Programming (OOP) C C++ Provides malloc() (calloc()) C++ provides new operator for Does not provide namespaces Namespaces are available for dynamic memory allocation memory allocation OOP is a way how to design a program to fulfill requirements Exception handling is not easy Exception handling through Try and make the sources easy maintain. It provides free() function for It provides delete and (delete[]) in C and Catch block memory de-allocation operator for memory de-allocation Inheritance is not possible Inheritance is possible Abstraction – concepts (templates) are organized into classes Does not support for virtual and C++ supports virtual and friend Objects are instances of the classes Function overloading is not Function overloading is possible friend functions functions possible (i.e., functions with the same name) Encapsulation Polymorphism is not possible C++ offers polymorphism Functions are used for Objects (streams) can be use for Object has its state hidden and provides interface to communicate C supports only built-in data It supports both built-in and input/output, e.g., scanf() and input/output, e.g., std::cin and with other objects by sending messages (function/method calls) types user-defined data types printf() std::cout Inheritance Mapping between data and In C++ data and functions are Does not support reference Supports reference variables, Hierarchy (of concepts) with common (general) properties that are functions is difficult in C easily mapped through objects variables using & further specialized in the derived classes Does not support definition C++ supports definition C programs are saved in files C++ programs are saved in files Polymorphism (overloading) operators (overloading) of the operators with extension .c with extension .cc, .cxx or .cpp An object with some interface could replace another object with http://techwelkin.com/difference-between-c-and-c-plus-plus the same interface Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 16 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 17 / 49 Jan Faigl, 2016 BE5B99CPL – Lecture 10: OOP in C++ (Part 1) 19 / 49 Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix Differences between C and C++ Classes and Objects Constructor/Destructor Example – Class Matrix Class Object Structure Creating an Object – Class Constructor Describes a set of objects – it is a model of the objects and defines:

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    5 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us