This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

如何保证或确认代码执行顺序不被优化?



您好,我需要让一段代码按照确定的顺序执行,并且我开启了O2优化,编译器版本是18.12.3LTS。请问如何保证或确认代码仍然按照顺序执行?

我需要按顺序执行的代码类似于:

a = 1;

b = a + 2;

c = b + 3;...

我需要确认这段代码是按顺序执行的,请问有方法吗?

谢谢