简体   繁体   中英

How do I disable the volatile storage class using command-line options to the compiler?

Is there any way to disable the volatile storage class using only compiler settings/flags while compiling in gcc without modifying the underlying source code ?

Ex.

volatile int x;
.. use x ..

Needs to be compiled as if it were written:

int x;
.. use x ..

Compile using

gcc -Dvolatile="" ...

so that the preprocessor will replace each occurrence of volatile with an empty string. If you were to just use -Dvolatile , volatile would be replaced with 1, which would cause compilation errors.

Because volatile keyword tells the compiler that the value may change at any point and that it should never cache the value, omitting them from working code will likely cause bugs to appear (as the compiler will sometimes work on stale values).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM