Questions about warnings
I'm looking over the VC build trying to eliminate what warnings are
left. One thing that appears in a couple of places is stuff like:
.\src\bin\psql\print.c(2014): warning C4090: 'function' : different
'const' qualifiers
This happens in psql when we do free() on a variable that's "const char
**". The same thing happens in oracle_compat.c in the backend with
pfree().
Is this a warning we should care about and remove (or change?) the const
qualifyer? Or should I just ignore it?
//Magnus
Magnus Hagander wrote:
I'm looking over the VC build trying to eliminate what warnings are
left. One thing that appears in a couple of places is stuff like:.\src\bin\psql\print.c(2014): warning C4090: 'function' : different
'const' qualifiersThis happens in psql when we do free() on a variable that's "const
char **". The same thing happens in oracle_compat.c in the backend
with pfree().
The code in question is:
const char **headers;
[...]
free(headers);
Is this a warning we should care about and remove (or change?) the
const qualifyer? Or should I just ignore it?
My free() takes a pointer to void, which should be able to point to any
type of data, and certainly pointer to pointer to const char fits that
description. So I think the compiler is overly zealous.
Actually writing into the supposedly constant data pointed to by
a "const type *" pointer would be a potential bug, but GCC catches
that, so we can be reasonably assured that this is OK in the current
code.
--
Peter Eisentraut
http://developer.postgresql.org/~petere/
"Peter Eisentraut" <peter_e@gmx.net> writes:
The code in question is:
const char **headers;
[...]
free(headers);
Perhaps it ought not be declared "const char **headers" if you're planning on
freeing it? I mean, it's not like you can pass an actual pointer to constant
memory to this function and expect it to work, and who says free doesn't
modify the data the pointer points to anyways, plenty do.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
On Thu, Jan 25, 2007 at 01:38:14PM +0100, Peter Eisentraut wrote:
Magnus Hagander wrote:
I'm looking over the VC build trying to eliminate what warnings are
left. One thing that appears in a couple of places is stuff like:.\src\bin\psql\print.c(2014): warning C4090: 'function' : different
'const' qualifiersThis happens in psql when we do free() on a variable that's "const
char **". The same thing happens in oracle_compat.c in the backend
with pfree().The code in question is:
const char **headers;
[...]
free(headers);
Right, and similar code for pfree().
Is this a warning we should care about and remove (or change?) the
const qualifyer? Or should I just ignore it?My free() takes a pointer to void, which should be able to point to any
type of data, and certainly pointer to pointer to const char fits that
description. So I think the compiler is overly zealous.Actually writing into the supposedly constant data pointed to by
a "const type *" pointer would be a potential bug, but GCC catches
that, so we can be reasonably assured that this is OK in the current
code.
I won't claim to know the inners good enough to comment on it. Does
"const char **" really mean that the point is const, or the pointer that
it points to is const?
Anyway, I'll just ignore the warnings then. I'll leave them enabled
in the compiler since they might catch other similar things that are
actually bugs in the future, and it's only 6 warnings in psql and 2 in
oracle_compat in total..
//Magnus
"Magnus Hagander" <magnus@hagander.net> writes:
I won't claim to know the inners good enough to comment on it. Does
"const char **" really mean that the point is const, or the pointer that
it points to is const?
"const char **" means the character at the end of the pointer chain is
constant. Which means my previous message is misguided, ignore it, sorry. In
short, yes, this is a limitation of the const syntax in C and you have to cast
it away in this case.
--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
On Thu, 25 Jan 2007, Magnus Hagander wrote:
I'm looking over the VC build trying to eliminate what warnings are
left. One thing that appears in a couple of places is stuff like:.\src\bin\psql\print.c(2014): warning C4090: 'function' : different
'const' qualifiers
Seems like other projects have encountered this problem. Looks like a
simple type difference. Casting to (void *) should fix it.
http://mirror.ethereal.com/lists/ethereal-dev/200502/msg00170.html
Gavin
On Fri, Jan 26, 2007 at 12:26:45AM +1100, Gavin Sherry wrote:
On Thu, 25 Jan 2007, Magnus Hagander wrote:
I'm looking over the VC build trying to eliminate what warnings are
left. One thing that appears in a couple of places is stuff like:.\src\bin\psql\print.c(2014): warning C4090: 'function' : different
'const' qualifiersSeems like other projects have encountered this problem. Looks like a
simple type difference. Casting to (void *) should fix it.http://mirror.ethereal.com/lists/ethereal-dev/200502/msg00170.html
The question is if we care enough. I'll be happy to provide a patch or
just a list of locations where it happens if that's what's wanted.
//Magnus
On Thu, Jan 25, 2007 at 01:20:10PM +0000, Gregory Stark wrote:
"const char **" means the character at the end of the pointer chain is
constant. Which means my previous message is misguided, ignore it, sorry. In
short, yes, this is a limitation of the const syntax in C and you have to cast
it away in this case.
Well, you can say things like:
char * const *ptr
Which means that *ptr is const, but ptr and **ptr are not. Each of
those can be made const/not const as desired...
What is intended here is quite a different question, the use of pointers
in that part of psql is a bit haphazard at times. FWIW, Coverity
complains about stuff here too, but I just marked it all WONTFIX :).
Have anice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
Show quoted text
From each according to his ability. To each according to his ability to litigate.
Gavin Sherry wrote:
On Thu, 25 Jan 2007, Magnus Hagander wrote:
I'm looking over the VC build trying to eliminate what warnings are
left. One thing that appears in a couple of places is stuff like:.\src\bin\psql\print.c(2014): warning C4090: 'function' : different
'const' qualifiersSeems like other projects have encountered this problem. Looks like a
simple type difference. Casting to (void *) should fix it.http://mirror.ethereal.com/lists/ethereal-dev/200502/msg00170.html
But note that Tom recently (correctly) chided me thus:
Oh, and casting away const gets no points for style.
cheers
andrew