From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25012 invoked by alias); 21 Apr 2003 21:25:39 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 25005 invoked from network); 21 Apr 2003 21:25:38 -0000 Received: from unknown (HELO nile.gnat.com) (205.232.38.5) by sources.redhat.com with SMTP; 21 Apr 2003 21:25:38 -0000 Received: by nile.gnat.com (Postfix, from userid 338) id 9373FF2C2C; Mon, 21 Apr 2003 17:25:38 -0400 (EDT) To: ghazi@caip.rutgers.edu, gp.bolton@computer.org Subject: Re: Const warning? (was: Re: [Patch] More redundant...) Cc: gcc@gcc.gnu.org, pcarlini@unitus.it Message-Id: <20030421212538.9373FF2C2C@nile.gnat.com> Date: Tue, 22 Apr 2003 00:07:00 -0000 From: dewar@gnat.com (Robert Dewar) X-SW-Source: 2003-04/txt/msg01018.txt.bz2 > > I'm glad to hear that there may already be a patch to have a "const" > warning! I can certainly see that pointers to pointers to pointers etc. > would be more difficult to do, especially since const can be at any level. > > To me, it is certainly worth having a warning if it can result in faster > compile times and/or better code being generated. > > As Paolo says, ideally the compiler would be able to generate the same > code whether variables are marked const or not. However, this is maybe > not realistic. So maybe it would just be a good idea to encourage use > of const to save the compiler from having to do all the analysis to > determine that a variable is const. > Two points. First of all, I think the warning is very valuable even if it does not cover the pointer case fully (don't let best be the enemy of good). Most certainly we have found this valuable in Ada. Second, I think the issue of better code is besides the point. It contributes significantly to the readability and maintainability of code to label constant objects as constant, since you do not have to worry about the possibility of them being changed. So this is something that should be done as a matter of style. Since for a long time C lacked this capability, C (and C++) programmers are not in the habit of designated things as constant when they should, and a nudge from the compiler is helpful.