Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Jun 2001 16:27:27 -0400 (EDT)
From:      Thomas David Rivers <rivers@dignus.com>
To:        msmith@FreeBSD.ORG, rivers@dignus.com
Cc:        hackers@FreeBSD.ORG, jhb@FreeBSD.ORG, roam@orbitel.bg
Subject:   Re: free() and const warnings
Message-ID:  <200106082027.QAA51955@lakes.dignus.com>
In-Reply-To: <200106081826.f58IQ4r01256@mass.dis.org>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> >  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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200106082027.QAA51955>