visual c++ .net 2003 bug in c4090 waring

G

Guest

Hi

The C code (not C++) below (test.c) generates a warning:

#include <stdlib.h>
int main()
{
const char** a = (const char**) malloc(1*sizeof(const char*));
a[0] = "boo";
free(a);
return(0);
}

If I compile above with MSVC 7.1:

I:\tmp>cl test.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights reserved.

test.c
test.c(6) : warning C4090: 'function' : different 'const' qualifiers
Microsoft (R) Incremental Linker Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe
test.obj

I believe this is not correct as I am not freeing the const data that is
being pointed to, only the non-const array of pointers.

Is this a compiler bug or am I missing sometihng?

Thanks,
Murali
--
 
D

David Lowndes

The C code (not C++) below (test.c) generates a warning:
...
If I compile above with MSVC 7.1:

Murali,

It also does with VC2005 if compiled as 'C' code.

The Comeau online compiler doesn't object, so it may well be an issue
with the MS compiler. I suggest that you submit a bug report on it
against VC2005 (mention that VC2003 is the same too):

http://lab.msdn.microsoft.com/productfeedback/

Post back a link to your bug report and I'll confirm it.

Dave
 
G

Guest

Hi Dave:

Here is the bug report I created:

http://lab.msdn.microsoft.com/Produ...edbackid=6f13f802-3e34-4044-b576-910a36a493ab

A similar one appears to have been reported already (and is marked
not reproducible, not sure why), albeit with regards to memset, but I
think the problem is the same.

http://lab.msdn.microsoft.com/produ...edbackid=4c726e9e-0586-48cc-bbaf-95ddb65117e9

Regards,
Murali
--

PS: On an unrelated note, I first tried reporting this as a bug by going to
microsoft.com. I was expecting to find a link where I could put in the
relavant
info and press submit. The best I could do was find this newgroup to post.
Later in the day a collegue pointed me to the lab.* link you mention, I am a
bit
surprised that a link to report bugs (free QE from my point of view) is not
easily found on from the support.microsoft.com web-ste.

-------
 
G

Guest

I noticed MS closed it out as by design. I very strongly disagree and it's
sort of a pain for us at our organization because we use -Werr and
simultaneously use different compilers.

You might want to reopen the bug (please). The resopnse from Microsoft
demonstrates a misunderstanding of the const modifier and ANSI C. You are
correct that char ** is compatible with void *.

The warning would be valid if the paramter being passed was const char *
const *.
 
D

David Lowndes

You might want to reopen the bug (please). The resopnse from Microsoft
demonstrates a misunderstanding of the const modifier and ANSI C. You are
correct that char ** is compatible with void *.

I've re-opened it - let's hope for a better response this time!

Dave
 
G

Guest

I wish I could quote chapter and verse of ANSI C-99 to which this applies.
If your organization happens to have a copy, try quoting it so you don't have
to defer to the authority of another compiler. Their C++ compiler does
properly handle this by the way.

I mis-typed in the earlier response. I meant to say const char ** is
compatible with void *, not char ** (which of course is also compatible).

In the meantime you can silence the warning with an explicit cast to (void
*), defeating the const violation checking.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top