Say for very common math functions, such as sin, cos, etc... does the compiler realise they have no side effects and have the ability to move them to outer loops? For examp
GCC has two attributes, pure
and const
, that may be used to mark such function. If the function has no side-effect and its result depends only on its arguments, the function should be declared const
, if the results may also depend on some global variable the function should be declared pure
. Recent versions also have a -Wsuggest-attribute
warning option that can point functions which ought to be declared const
or pure
.