[prev in list] [next in list] [prev in thread] [next in thread] 

List:       cfe-dev
Subject:    Re: [cfe-dev] Proposal: A "Const tool" for clang
From:       Dmitri Gribenko <gribozavr () gmail ! com>
Date:       2013-02-05 5:58:57
Message-ID: CA+Y5xYdHv44MthNeCm_aK4v42FJbbafwmYV0+jZ2ycrriGyZ4w () mail ! gmail ! com
[Download RAW message or body]

On Tue, Feb 5, 2013 at 2:55 AM, Marshall Clow <mclow.lists@gmail.com> wrote:
> Broadly speaking, there are three places where const can be added to an existing \
>                 code base:
> * Parameters that are passed by reference or pointer can be passed by const pointer \
>                 or const reference.
> * object methods can be marked as const
> * Return values that are returned by pointer or reference can be returned by const \
> reference or const pointer. This may involve adding an additional function \
> alongside the original, differing only in the return value.

Local variables might require adding 'const', too.  A dumb example:

int f(Z *z) {
  Z *a = z->getA();
  return a->getInt();
}

If there's a const and non-const overload of getA() and getInt(), then
one can actually add const everywhere in this example.

Dmitri

-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/
_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic