[PATCH] declare file-scoped globals "static"; use const, too

Pete Zaitcev zaitcev at redhat.com
Mon Oct 4 15:53:13 UTC 2010


On Mon, 04 Oct 2010 17:39:16 +0200
Jim Meyering <jim at meyering.net> wrote:

> Think of strcpy, memcpy(d, s, n), etc.  If the SRC parameter were not
> const, how many beginners would mistakenly reverse the src and dest args?

Haha. I never saw that happen, because the result is very evident
even to beginner. So, it's a nonproblem, in comparison, for example,
with memset(p, 0, sizeof(*p)).

> With "const" there, and const used religiously in the calling application,
> there is much less risk.

Hardly worth bothering, IMHO.

> Also, if you forget const on a pointer in an API, you're guaranteed
> to annoy (to say the least) any const-correct users of your library.

Exactly. Significant downsides, lots of wasted effort for no benefit.

-- Pete


More information about the iwhd-devel mailing list