































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































Chapter Eight Modern Programming Languages, 2nd ed. (^) Docsity.com 1
Chapter Eight Modern Programming Languages, 2nd ed. 2
int f(char a, char b) { return a==b; }
- fun f(a, b) = (a = b); val f = fn : ''a * ''a -> bool
Docsity.com
Chapter Eight Modern Programming Languages, 2nd ed. (^) Docsity.com 4
Chapter Eight Modern Programming Languages, 2nd ed. (^) Docsity.com 5
Chapter Eight Modern Programming Languages, 2nd ed. 7
class complex { double rp, ip; // real part, imaginary part public: complex(double r, double i) {rp=r; ip=i;} friend complex operator+(complex, complex); friend complex operator(complex, complex); };*
void f(complex a, complex b, complex c) { complex d = a + b * c; … }
Docsity.com
Chapter Eight Modern Programming Languages, 2nd ed. (^) Docsity.com 8
Chapter Eight Modern Programming Languages, 2nd ed. 10
int square(int x) { return xx; }*
double square(double x) { return xx; }*
void f() { int a = square(3); double b = square(3.0); }
You could rename each overloaded definition uniquely…
square_i
square_d
Docsity.com
Chapter Eight Modern Programming Languages, 2nd ed. 11
int square_i(int x) { return xx; }*
double square_d(double x) { return xx; }*
void f() { int a = square_i(3); double b = square_d(3.0); }
Then rename each reference properly (depending on the parameter types)
Docsity.com
Chapter Eight Modern Programming Languages, 2nd ed. 13
int shazam(int a, int b) {return a+b;} double shazam(double a, double b) {return a+b;}
shazam__Fii: lda $30,-32($30) .frame $15,32,$26, … shazam__Fdd: lda $30,-32($30) .frame $15,32,$26, …
Assembler:
Docsity.com
Chapter Eight Modern Programming Languages, 2nd ed. (^) Docsity.com 14
Chapter Eight Modern Programming Languages, 2nd ed. (^) Docsity.com 16
Chapter Eight Modern Programming Languages, 2nd ed. 17
void f(double x) { … }
f((byte) 1); f((short) 2); f('a'); f(3); f(4L); f(5.6F);
This f can be called with any type of parameter Java is willing to coerce to type double
Docsity.com
Chapter Eight Modern Programming Languages, 2nd ed. 19
Some operators apply unary numeric promotion to a single operand, which must produce a value of a numeric type: If the operand is of compile-time type Byte , Short , Character , or Integer it is subjected to unboxing conversion. The result is then promoted to a value of type int by a widening conversion or an identity conversion. Otherwise, if the operand is of compile-time type Long , Float , or Double it is subjected to unboxing conversion. Otherwise, if the operand is of compile-time type byte , short , or char , unary numeric promotion promotes it to a value of type int by a widening conversion. Otherwise, a unary numeric operand remains as is and is not converted. In any case, value set conversion is then applied. Unary numeric promotion is performed on expressions in the following situations:
Docsity.com
Chapter Eight Modern Programming Languages, 2nd ed. (^) Docsity.com 20