Optimizations in IAR
--------------------


Project-Wide Optimizations
^^^^^^^^^^^^^^^^^^^^^^^^^^

Project ``Options`` |rarr| ``C/C++ Compiler`` |rarr| ``Optimizations``

.. figure:: /debugging/resources/iar_optim_level_project.png
    :align: center

    Project-level optimization setting in IAR


Single-File Optimizations
^^^^^^^^^^^^^^^^^^^^^^^^^

1. Right-click on the file in the Workspace pane.

2. Choose Options.

3. Check Override inherited Settings.

4. Choose the optimization level.


Single-Function Optimizations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. warning::
    Pragmas are very specific to the toolchain, and may lead to non-reusable
    code. Be careful where you use these.

Use #pragma optimize=none before the function definition to deoptimize the
entire function, that is, as follows.

.. code-block:: c
   :caption: Function-level optimization setting in IAR
   :emphasize-lines: 1

   #pragma optimize=none
   static void myFunction(int number)
   {
       // ...
       return yourFunction(other_number);
   }
