Politechnika Śląska - strona 148

Stream operators

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 497

Stream operators  Input friend istream & operator (istream &, T &);  Output friend ostream &operator (istream & s, point & p); friend ostream &operator p; cinpp2; cout p.x p.y; return s; } ostream &operator ...

The scope operator as a non-OO C++ extension

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 308

The scope operator as a non-OO C++ extension int fun(); int i; class C { int i; public: void test(); int fun(); }; void C::test() { i++; // C::i++ ::i++; // global i fun(); // C::fun() ::fun(); // global fun() } ...

Variable function argument list

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Computer Programming
Pobrań: 0
Wyświetleń: 399

Variable function argument list  in C we write: int printf(char *, …);  in C++ a bit simpler: int printf(char * …); // comma not required, but only if // variable preceding ”…” has no default value. // Macros for accessing args in (like in C)  ...

A simplified copying program

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 448

A simplified copying program #include #include #define PERMS 0666 /* RW for owner, group, others */ /* cp: copy f1 to f2 */ int main(int argc, char *argv[]) { int f1, f2, n; char buf[BUFSIZ]; if (argc != 3) fprintf(stderr,"Usage: cp from to"); if ((f1 = open(argv[1], O_RDONLY, 0)) == -1...

ANSI C Translation Phases

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 469

ANSI C Translation Phases  Every trigraph sequence in the source file is replaced  Every backslash/new-line character pair is deleted  The source is converted into preprocessing tokens and sequences of white spaces  Each comment is effectively replaced by a space character  Every preprocessing...

Conditional Inclusion

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 581

Conditional Inclusion  The #if line evaluates a constant integer expression  If the expression is non-zero, subsequent lines until an #endif or #elif or #else or #elifdef or #elifndef are included  The expression defined( name ) in a #if is 1 if the name has been defined, and 0 Otherwise 

Functions in C99

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 735

F unctions in C99  acosh  asinh  atanh  cbrt  copysign( x , y )  erf  erfc  exp2( x )  expm1( x )  fdim( x , y ) inverse hyperbolic cosine inverse hyperbolic sine inverse hyperbolic tangent cube root returns the value of x with the sign of y error function complementary error function rai...

Line buffered input

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 483

Line buffered input  Each line input is stored in a buffer  Problems can arise when a program does not process all the data in a line, before it wants to process the next line of input  Consider the following code: int x; char st[31]; printf(&qu...

Low Level IO

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 567

Low Level I/O - Read and Write int n_read = read(int fd, char *buf, int n); int n_written = write(int fd, char *buf, int n);  Each call returns a count of the number of bytes transferred  On reading, the number of bytes returned may be less than the number requested  A return value of zero bytes...

Macro substitution

  • Politechnika Śląska
  • dr inż. Piotr Fabian
  • Fundamentals of Computer Programming
Pobrań: 0
Wyświetleń: 567

Macro substitu tion  A definition has the form #define name replacement_text  Subsequent occurrences of the token name will be replaced by the replacement_text  The name in a #define has the same form as a variable name  The replacement text is arbitrary  The replacement text is the rest of th...