Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Disable GCC simplification of expressions known at compile time

Suppose I have the following C line:

int a = 4 + 7;

When compiling this line, GCC will always produce something like mov DWORD PTR [rbp-X], 0xb, as the result of this computation is constant and known at compile time. Is there a way to disable this behaviour to have a mov 4, add 7 instead?

A quick search led me to the -O0 or -OG flags, but they turn off other kinds of optimizations, such as the fact that functions should be aligned in memory.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is there a way to disable this behaviour to have a mov 4, add 7 instead?

No. Evaluation of elementary constant expressions is built into the compiler.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading