bug-gnulib
[Top][All Lists]
Advanced

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

Re: "const" scalars


From: Paul Eggert
Subject: Re: "const" scalars
Date: Mon, 12 Apr 2010 13:50:06 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

Jim Meyering <address@hidden> writes:

> By "local variables" you must mean "local scalar variables".
> You wouldn't argue for dropping "const" as a pointer attribute.

Yes, that's right.  That is, it's fine to have this:

       {
          char const *p = &a[i];
          ...
       }

because the 'const' is talking about p's value, not about p itself, and
the value's const-ness is often non-obvious.  In constrast, it's dubious
to have this:

       {
          char *const p = &a[i];
          ...
       }

because this 'const' is talking about p itself, and p is a local
variable so it is typically obvious (by inspecting the "...") whether p
varies.

> In any case, don't worry: I'm not about to add "const"
> to all scalar declarations.

Yay!  Thanks.




reply via email to

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