Re: free() and const warnings

2001-06-09 Thread Jacques A. Vidrine
On Sat, Jun 09, 2001 at 12:49:40AM -0700, Damien Neil wrote: > On Thu, Jun 07, 2001 at 12:47:30PM -0500, Jacques A. Vidrine wrote: > > C99 says of uintptr_t only that for any valid pointer p, the following > > is true: > > > > (void *)(uintptr_t)p == (void *)p > > > > Likewise for intptr_t.

Re: free() and const warnings

2001-06-09 Thread Damien Neil
On Thu, Jun 07, 2001 at 12:47:30PM -0500, Jacques A. Vidrine wrote: > C99 says of uintptr_t only that for any valid pointer p, the following > is true: > > (void *)(uintptr_t)p == (void *)p > > Likewise for intptr_t. I read that as covering both code and data > pointers. C89, at least,

Re: free() and const warnings

2001-06-08 Thread Matt Dillon
Oh my, and just posting these I found a couple of bugs! :char * :safe_replace(char **pptr, const char *s) :{ :/* : * Same data (also occurs if s == *ptr), nothing to do : */ :if (*pptr) { : if (s && strcmp(s, *pptr) == 0) : return(*pptr); : free(*pptr);

Re: free() and const warnings

2001-06-08 Thread Matt Dillon
Here is the whole set of supporting routines. -Matt /* * STRDUP.C * * $Backplane: backplane/src/libsupport/strdup.c,v 1.13 2001/04/03 00:03:18 dillon Exp $ */ #include "defs.h" Export char *safe_strdup(const char *s); Export char *safe_strdup_s

Re: free() and const warnings

2001-06-08 Thread Matt Dillon
:OK, here's a scenario: : :struct validation_fun { : const char *name; : valfun *fun; : int dyn; :}; : :This is a structure for a set of validation functions, referenced by :name from another type of object. There are some predefined functions, :present

Re: free() and const warnings

2001-06-08 Thread Thomas David Rivers
> > > 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

Re: free() and const warnings

2001-06-08 Thread Mike Smith
> 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. -- ... every activity me

Re: free() and const warnings

2001-06-08 Thread T. William Wells
> E.. 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 - Not all -W options are equally useful and some are actively harmful. This is one of them. There are several situations where it is necessary to remove a quali

Re: free() and const warnings

2001-06-08 Thread Peter Pentchev
On Fri, Jun 08, 2001 at 03:09:53PM +0200, Assar Westerlund wrote: > Peter Pentchev <[EMAIL PROTECTED]> writes: > > My explanation was a reply to a suggestion to remove the 'const' in > > the structure definition. > > My fault. The code that I should have shown was without the 'const'. > With gcc

Re: free() and const warnings

2001-06-08 Thread Assar Westerlund
Peter Pentchev <[EMAIL PROTECTED]> writes: > My explanation was a reply to a suggestion to remove the 'const' in > the structure definition. My fault. The code that I should have shown was without the 'const'. With gcc 2.95.3 and 'gcc -O -g -Werror -Wall -W -Wcast-qual -c foo.c' I don't get any

Re: free() and const warnings

2001-06-08 Thread Peter Pentchev
On Fri, Jun 08, 2001 at 03:02:56PM +0200, Assar Westerlund wrote: > Peter Pentchev <[EMAIL PROTECTED]> writes: > > GCC complains when I try to initialize the structure with something like: > > > > struct validation_fun val_init[] = { > > {"init",valfun_init,0} > > }; > > >

Re: free() and const warnings

2001-06-08 Thread Assar Westerlund
Peter Pentchev <[EMAIL PROTECTED]> writes: > 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 *)

Re: free() and const warnings

2001-06-08 Thread Thomas David Rivers
> > 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 avoide

Re: free() and const warnings

2001-06-08 Thread Peter Pentchev
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: > > > > st

Re: free() and const warnings

2001-06-08 Thread Thomas David Rivers
> > 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}

Re: free() and const warnings

2001-06-08 Thread Peter Pentchev
On Fri, Jun 08, 2001 at 06:55:50AM -0400, Thomas David Rivers wrote: > Peter Pentchev <[EMAIL PROTECTED]> wrote: > > > > On Thu, Jun 07, 2001 at 10:20:51AM -0700, John Baldwin wrote: > > > > > > On 07-Jun-01 Peter Pentchev wrote: > > > > On Thu, Jun 07, 2001 at 07:07:22PM +0300, Peter Pentchev w

Re: free() and const warnings

2001-06-08 Thread Thomas David Rivers
Peter Pentchev <[EMAIL PROTECTED]> wrote: > > On Thu, Jun 07, 2001 at 10:20:51AM -0700, John Baldwin wrote: > > > > On 07-Jun-01 Peter Pentchev wrote: > > > On Thu, Jun 07, 2001 at 07:07:22PM +0300, Peter Pentchev wrote: > > >> Hi, > > >> > > >> Is free((void *) (size_t) ptr) the only way to fr

Re: free() and const warnings

2001-06-08 Thread Peter Pentchev
On Thu, Jun 07, 2001 at 10:20:51AM -0700, John Baldwin wrote: > > On 07-Jun-01 Peter Pentchev wrote: > > On Thu, Jun 07, 2001 at 07:07:22PM +0300, Peter Pentchev wrote: > >> Hi, > >> > >> Is free((void *) (size_t) ptr) the only way to free a const whatever *ptr > >> with WARNS=2? (or more speci

Re: free() and const warnings

2001-06-07 Thread Warner Losh
In message <[EMAIL PROTECTED]> John Baldwin writes: : Of course, this begs the question of why you are free'ing a const. :) Sometimes that's the only handle that you have on the object :-). I sometimes think that changing free to be const void * is the right answer, but that has its own set prob

Re: free() and const warnings

2001-06-07 Thread Jacques A. Vidrine
On Thu, Jun 07, 2001 at 10:20:51AM -0700, John Baldwin wrote: > > On 07-Jun-01 Peter Pentchev wrote: > > On Thu, Jun 07, 2001 at 07:07:22PM +0300, Peter Pentchev wrote: > >> Hi, > >> > >> Is free((void *) (size_t) ptr) the only way to free a const whatever *ptr > >> with WARNS=2? (or more speci

Re: free() and const warnings

2001-06-07 Thread John Baldwin
On 07-Jun-01 Peter Pentchev wrote: > On Thu, Jun 07, 2001 at 07:07:22PM +0300, Peter Pentchev wrote: >> Hi, >> >> Is free((void *) (size_t) ptr) the only way to free a const whatever *ptr >> with WARNS=2? (or more specifically, with -Wcast-qual) > > Uhm. OK. So size_t may not be enough to ho

Re: free() and const warnings

2001-06-07 Thread Peter Pentchev
On Thu, Jun 07, 2001 at 07:07:22PM +0300, Peter Pentchev wrote: > Hi, > > Is free((void *) (size_t) ptr) the only way to free a const whatever *ptr > with WARNS=2? (or more specifically, with -Wcast-qual) Uhm. OK. So size_t may not be enough to hold a pointer. What is it then - caddr_t? G'l

free() and const warnings

2001-06-07 Thread Peter Pentchev
Hi, Is free((void *) (size_t) ptr) the only way to free a const whatever *ptr with WARNS=2? (or more specifically, with -Wcast-qual) G'luck, Peter -- I've heard that this sentence is a rumor. To Unsubscribe: send mail to [EMAIL PROTECTED] with "unsubscribe freebsd-hackers" in the body of the