[Top][All Lists]

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

Re: [PATCH 4/5] qualify constant with the const

From: Ivan Shmakov
Subject: Re: [PATCH 4/5] qualify constant with the const
Date: Mon, 16 Sep 2013 06:47:10 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

>>>>> Marin Ramesa <mpr@hi.t-com.hr> writes:
>>>>> On 11.09.2013 22:14:49, Samuel Thibault wrote:
>>>>> Marin Ramesa, le Wed 11 Sep 2013 12:27:50 +0200, a écrit :

 >>> Function cnputc() should never modify it's argument so qualify it
 >>> with a const keyword.

 >>>  void
 >>>  cnputc(c)
 >>> -  char c;
 >>> +  const char c;

 >> Well, this is not really useful: the function gets a copy of the
 >> argument anyway.

 > Yes, but the const protects the copy.  It expresses the intent of the
 > function.  It's like saying to the caller: "I will behave nicely and
 > not modify the passed value during my execution."  Then the caller
 > knows that the value of the variable after the function is the same
 > that was in the function.

        Which variable will that be if cnputc () is used as follows?

   cnputc (10);

        The point is that const char is the same as char as long as the
        /caller/ is concerned.  As for the callee, it indeed protects
        the local variable there from being modified, which may help one
        to spot the code overriding (perhaps unintentionally) the value
        passed as an argument.  However, my guess is that it’d rarely be
        all that useful in the cases like the one presented.


FSF associate member #7257      http://sf-day.org/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]