On Thu, 11 Mar 2021 at 19:35, Hugo Musso Gualandi <hgualandi@xxxxxxxxxxxxxx> wrote: > > > > Did you try the access attribute? > > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > > Oh, I didn't know about this one. But it doesn't seem to change the > generated code... Maybe it is only used for diagnostic error messages? Yes, it doesn't seem to be used by the optimizers. I assumed it would be, based on this statement in the manual: "The mode implies a stronger guarantee than the const qualifier which, when cast away from a pointer, does not prevent the pointed-to object from being modified." > > Or for older versions of GCC using the pure attribute seems to work as > > you want too. > > Unfortunately, the reader function in the example is not pure. > Annotating it with __attribute__((pure)) causes GCC to warn about the > "void" return type and the function call is completely removed from the > generated code. Ah yes, using 'pure' obviously won't work if it does modify other state, just not the pointer you pass to it!