cs375 p. 259

Contents Page-10 Prev Next Page+10 Index

Constant Folding

Constant folding is performing operations on constants at compile time:

x = angle * 3.1415926 / 180.0
y = sqrt(2.0)
z = a[3]

The savings from doing this on programmer expressions is minor. However, there can be major savings by optimizing:

  1. Subscript expressions generated by the compiler.

  2. Messages in an object-oriented language.

Constant folding should not allow the programmer to ``break'' the compiler by writing a bad expression: sqrt(-1.0).

AltStyle によって変換されたページ (->オリジナル) /