Re: Disable optimizations on one function (was: 'pragma optimize' ...)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 16/07/15 06:58, Jeffrey Walton wrote:
> Many folks try and cast ptr to volatile, but that's an abuse because
> GCC considers volatile something for memory mapped hardware. Volatile
> should not be used in an attempt to tame the optimizer.

GCC does not consider volatile to be something for memory mapped
hardware.  Volatile objects are simply those which may be modified in
ways unknown to the implementation or have other unknown side effects.
In other words, volatile is exactly the right thing use in the
ClearAndFree case.  But passing a volatile pointer to memset() is
pointless because the volatile qualifier will be discarded at the
point of call: you'll have to write the memory yourself.

If you don't mind being nonportable, a memoryclobber should do it:

    memset(ptr, 0x00, n);
    asm volatile("": : : "memory");

or even:

    memset(ptr, 0x00, n);
    __atomic_thread_fence(__ATOMIC_RELAXED);

Andrew.



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux