On 22 August 2013 10:58, Roberto E. Vargas Caballero <k0ga_AT_shike2.com> wrote:
>
> Since r is a local variable doesn't matter if
> the function modifies it (and even is better modify it instead of
> using other local variable for it). I use const only when I want
> show that the function is going to accept constant string which
> should not be modified, like for example:
>
> printf(const char *fmt, ...)
>
This is true; implementation-wise on x86-64, local variables are
stored in registers and in low-register architectures, like the i386 -
it's on the stack (local variables from parameters). As far as I
know, in all cases of modern hardware, it's more beneficial to lift
the const restriction. Of course, a 'good' compiler would see both
versions (const and non-const) and generate the most optimal code :) .
The only conceivable use in that context is if you were doing some
form of design-by-contract. However, in that case I'd suggest that C
isn't the right language to use if that was the intention.
Cheers,
Ralph
--
Tai Chi Minh Ralph Eastwood
tcmreastwood_AT_gmail.com
Received on Thu Aug 22 2013 - 12:19:19 CEST