Re: Warning on useless 'const' in a function declaration

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

 



On Wed, 9 Oct 2024 at 14:03, Andrew C Aitchison via Gcc-help <
gcc-help@xxxxxxxxxxx> wrote:

>
> On Mon, 7 Oct 2024, Jonathan Wakely via Gcc-help wrote:
> >
> > I think the question is about the 'const' in the non-defining
> > declaration of the function, i.e. "the prototype" in C
> > terminology. It's meaningful on the function definition, but adding
> > or removing it on the decl in the header makes no difference to
> > anything.
>
> Are there any circumstances where knowing that the arg is const means
> that the value does not need to be copied/saved before calling the
> function ?  One possible case is a wrapper function which immediately
> calls the wrapped function, then does something with the arguments ?
>
> Even with call by value, I imagine that there are optimizations that
> can be done when the compiler writes a function call knowing that
> arguments are declared const.
>

No.

If the function is not being inlined, then such a change would break the
function call ABI.

If a function is being inlined, then what matters is what the function body
does. If the parameter isn't changed, then the compiler can take advantage
of that whether it's declared const or not.



[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