The const function attribute

The const function attribute allows you to tell the compiler that the function can safely be called fewer times than indicated in the source code. The language feature provides you with an explicit way to help the compiler optimize code by indicating that the function does not examine any values except its arguments and has no effects except for its return value.

Read syntax diagramSkip visual syntax diagramconst function attribute syntax
 
>>-__attribute__--((--+-const-----+--))------------------------><
                      '-__const__-'
 

The following kinds of functions should not be declared const:

Related information