In article <11**********************@m58g2000cwm.googlegroups .com>,
subramanian <su**************@yahoo.comwrote:
>Consider the following program:
>#include <stdio.h>
>void myfn(const int **a)
{
>}
>int main(void)
{
int *a[3];
> myfn(a);
return 0;
}
>the following Compilation warning is produced with gcc
const_ptr.c: In function `main':
const_ptr.c:27: warning: passing arg 1 of `myfn' from incompatible
pointer type
>If I remove the const qualifier in myfn( ), the program compiles with
gcc without any warning.
>Why is the warning generated with gcc ?
An array name mentioned outside of a & or sizeof construct decays
into a pointer to the first of its elements. It does -not- decay
into a const pointer to that element, and it does -not- const
qualify the elements of the array... not unless those elements
were declared const to begin with. The warning is thus correct:
you are passing something that is not declared const into a routine
that is expecting a const.
>However with VC++ 2005, there is no compilation warning with the
original program ie even when the const qualifier is present.
Compilers are required to produce diagnostics if constraints
are violated, but whether those diagnostics are labeled as
"error" or "warning" or "note" or "Look At This!" is up to
the compiler.
A compiler is not required to stop compiling upon detecting something
interesting -- not unless it is an #error construct that is in full effect.
A compiler is allowed to produce any number of warnings or notes
that it wants, as long as it compiles code that does not violate
constaints.
The exact set of non-required diagnostics that a compiler produces
is a Quality of Implementation Issue (usually called QoI around here).
For the most part, compilers that produce valid diagnostics are
usually considered to be of higher quality than those which do not
bother to produce the diagnostic. We'll leave you to your own
conclusions as to what this implies about the relative worths
of gcc and VC++ 2005.
--
Is there any thing whereof it may be said, See, this is new? It hath
been already of old time, which was before us. -- Ecclesiastes