const volatile

Xi Ruoyao xry111@mengyan1223.wang
Wed Sep 26 13:18:00 GMT 2018


On 2018-09-26 13:54 +0100, Kalamatee wrote:
> Hi
> 
> I am wondering if there is a reason globals marked const volatile are
> put
> into the data section and not read-only as const should imply?
> 
> I am trying to compile code for m68k AmigaOS which is resident using
> the
> mathlib functions which need certain constants as volatile to prevent
> incorrect sequence re-ordering in gcc's optimizations - however doing
> so
> puts the value in bss data without const.
> 
> How can we have a global that is both volatile (to prevent incorrect
> sequencing) and const (so it is read only and stored in read only
> data
> section) ?

"const" means your program should not modify it.  "volatile" means
other things (invisible to your program) may modify it.

For example, a microcontroller's 8 input pins can be described as
"const volatile uint8_t mcu_input_1" in its C header.
-- 
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University



More information about the Gcc-help mailing list