dandelion said:
Like you would any other integer. Assign it to ordinary 'int' and do
whatever it is you want to do.
<example code>
[snip]
No, that's not modifying the result, it's modifying the value of a
*copy* of the result.
The function in question has been lost in snippage; it looked
something like this:
const int get_foobar(int i)
{
return blah;
}
Declaring the function to return a "const int" does not imply that the
caller shouldn't modify the value of a copy of the result. Indeed, it
would almost certainly be absurd to suggest such a thing. The copy is
the caller's own variable, no longer associated iwth the function in
any way, and the caller can do whatever it likes with it.
C provides no mechanism to even *attempt* to modify the actual result
of a function, any more than it allows you to modify a constant such
as 42. A function result is an rvalue.
An attempt to modify the function result might look like this:
get_foobar(2) = 10; /* illegal */
but of course that's not valid C, any more than
42 = 10; /* illegal */
is.
C allows you to declare that a function returns a const result, but
it's completely useless to do so, even as a hint to the programmer.
(Conceivably you could add a "const" to a function declaration to
force a pointer to that function to be incompatible with some other
function pointer, but that's ugly, and I'm not sure you can depend on
the compiler to enforce it.)