From owner-freebsd-hackers Fri Jun 8 13:25:15 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from fjord.dignus.com (sdsl-66-80-58-206.dsl.lax.megapath.net [66.80.58.206]) by hub.freebsd.org (Postfix) with ESMTP id F26CF37B403; Fri, 8 Jun 2001 13:25:11 -0700 (PDT) (envelope-from rivers@dignus.com) Received: from lakes.dignus.com (lakes.dignus.com [10.0.0.3]) by fjord.dignus.com (8.11.1/8.11.1) with ESMTP id f58KQ8f01076; Fri, 8 Jun 2001 16:26:08 -0400 (EDT) (envelope-from rivers@dignus.com) Received: (from rivers@localhost) by lakes.dignus.com (8.9.3/8.6.9) id QAA51955; Fri, 8 Jun 2001 16:27:27 -0400 (EDT) Date: Fri, 8 Jun 2001 16:27:27 -0400 (EDT) From: Thomas David Rivers Message-Id: <200106082027.QAA51955@lakes.dignus.com> To: msmith@FreeBSD.ORG, rivers@dignus.com Subject: Re: free() and const warnings Cc: hackers@FreeBSD.ORG, jhb@FreeBSD.ORG, roam@orbitel.bg In-Reply-To: <200106081826.f58IQ4r01256@mass.dis.org> 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 > > > Since some strings are non-constant (the are allocated) - I believe > > the `const' qualifier in the structure declaration is incorrect. > > 'const' just means "I will not be modifying this"; it's a way for a > function prototype to constrain the function's implementation. > Yes - it is.. However, "a string" is a const array of char. malloc(9) isn't. (And, can't be, since you have to, presumably, malloc the space and then write something meaningful to it...) So, if you declare a variable as const char * and then have different "constness" in assigning to that data, you are asking for the one variable to be both `const' and non-`const'... I was taking it from the "other side" (not the call to free() side, but the declaration of the data type...) Saying that the datum isn't actually `const' - it's only "sometimes const" (and only during the static initialization.) "sometimes const" doesn't make sense... But - then, if you remove the `const' - you get warnings from the initialization - assigning a pointer-to-const to a pointer-to-non-const. So... what's a programmer to do? That's the issue, right? - Dave R. - -- rivers@dignus.com Work: (919) 676-0847 Get your mainframe programming tools at http://www.dignus.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message