Is there a way to force the Arduino compiler to compile individual commands sequentially? Looking at the disassembly, lines of the assembly code for different C/Arduino commands are mixed. I was thinking something like a dmb or dsb command in ARM assembly. I realize it's done the way it is for timing optimization, but I would like to see if changing it fixes some other timing issues I'm having. I'm working on an Arduino Zero. Thanks!

1 Answer 1


You can use the optimize function attribute to change the compiler optimization level for an individual function. That's the closest you'll get.


The optimize attribute is used to specify that a function is to be compiled with different optimization options than specified on the command line. Arguments can either be numbers or strings. Numbers are assumed to be an optimization level. Strings that begin with O are assumed to be an optimization option, while other options are assumed to be used with a -f prefix. You can also use the #pragma GCC optimize pragma to set the optimization options that affect more than one function. See Function Specific Option Pragmas, for details about the #pragma GCC optimize pragma.

This attribute should be used for debugging purposes only. It is not suitable in production code.


void __attribute__((optimize("O0"))) myFunction() {
    // ...
  • From what I saw, the default optimization option is -O0, which is also the lowest level of optimization. Is that correct? I didn't see one but I want to make sure, is there an option to disable this kind of timing optimization?
    – Alexandra
    Jul 13, 2016 at 20:18
  • 3
    No. Simply because there isn't really a 1:1 relationship between C code and Assembly code. If you want specific instructions in a specific order you will have to write assembly code directly. However, instruction ordering is highly unlikely to be the cause of some unspecified errors you may be having. I suspect you are suffering from an XY Problem and need to step back and look at the problem, not your (probably incorrect) assumption about the cause.
    – Majenko
    Jul 13, 2016 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.