logo
C and gcc optimisations
Storage classes & Qualifiers
The use of 'const'
The use of 'register'
The use of 'volatile'
The use of 'restrict'
gcc optimisations
Enable optimizations at compile

C and gcc optimisations

Storage classes & Qualifiers

The use of 'const'

Using 'const' in the prototype of a function ensures that the value of the variable will not be changed in this function. It is advisable to add 'const' whenever a variable does not change. So if you make a mistake in the algorithm, we will be "kindly insulted" by the compiler.

The use of 'register'

The use of 'register' allows you to specify that a variable should if possible be placed in a register. Modern compilers do this operation very well for us. Therefore, unless you are sure of yourself, it is not recommended to use it.

The use of 'volatile'

The use of "volatile" specifies the compiler that a variable can be modified by another program. It can be combined with 'const', in this case the variable can't be changed from the outside.

The use of 'restrict'

"Restrict" is used on pointers, to specify that only the pointer concerned points to this memory area. The compiler can then optimize the process..

gcc optimisations

Enable optimizations at compile

It is possible to specify to the compiler GCC optimizations to perform. Native optimizations modes a activated with the following options "-O, -O0, -O1, -O2, -O3, -Os". To see the detailed optimization of each mode, simply use the following command specifying the mode that you want to know the details:
gcc -c -Q -O0 --help=optimizers | grep enabled
Be The First To Comment.

Add a comment:





You can use these HTML tags: <br><a><i><b>