From owner-freebsd-hackers Fri Jun 8 5:56:47 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from ringworld.nanolink.com (ringworld.nanolink.com [195.24.48.13]) by hub.freebsd.org (Postfix) with SMTP id 6007637B405 for ; Fri, 8 Jun 2001 05:56:43 -0700 (PDT) (envelope-from roam@orbitel.bg) Received: (qmail 7898 invoked by uid 1000); 8 Jun 2001 12:55:28 -0000 Date: Fri, 8 Jun 2001 15:55:28 +0300 From: Peter Pentchev To: Thomas David Rivers Cc: hackers@FreeBSD.ORG, jhb@FreeBSD.ORG Subject: Re: free() and const warnings Message-ID: <20010608155527.D7671@ringworld.oblivion.bg> Mail-Followup-To: Thomas David Rivers , hackers@FreeBSD.ORG, jhb@FreeBSD.ORG References: <20010608154249.A7671@ringworld.oblivion.bg> <200106081251.IAA49852@lakes.dignus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200106081251.IAA49852@lakes.dignus.com>; from rivers@dignus.com on Fri, Jun 08, 2001 at 08:51:54AM -0400 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, Jun 08, 2001 at 08:51:54AM -0400, Thomas David Rivers wrote: > > > > GCC complains when I try to initialize the structure with something like: > > > > struct validation_fun val_init[] = { > > {"init", valfun_init, 0} > > }; > > > > This can be avoided by: > > > > struct validation_fun val_init[] = { > > {(char *) (uintptr_t) "init", valfun_init, 0} > > }; > > > > ..but as a matter of fact, static, pre-initialized valfun structs are > > the rule rather than the exception in this program, so having this > > syntax for all of them seems.. well.. ugly :) > > > > Ah.. I see.. > > (I don't think you need (uintptr_t) - you can cast a (const char *) > to a (char *) without having to go "through" that - I believe.) Errrr.. this was the whole point of this thread. I *can't* cast a (const char *) to a (char *) when using the -Wcast-qual gcc flag - the -Wcast-qual flag produces exactly this type of warnings, to make sure you don't treat const * pointers as normal pointers, and pass them to functions that do stupid things like modify them or free them :) > Is this C, or C++.. there are some differences in the type of > a constant character string between the two... > > But - basically, what you are trying to describe is a field which > is sometimes 'const' and othertimes isn't... which doesn't make > sense in the context of the C standard... you'll need a cast > for the initialization, or some other approach besides static > initialization I believe... (or, just "live" with the warning... > which isn't pleasant at all.) Well, I can't live with the warning with -Werror ;) So I guess I'll live with casting in free() :) G'luck, Peter -- If wishes were fishes, the antecedent of this conditional would be true. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message