D
d3x0xr
---- Section 1 ----
------
x.c
int main( void )
{
char **a;
char const *const *b;
b = a; // line(9)
}
------
wpp386 x.c
x.c(9): Warning! W1178: Type qualifier mismatch
x.c(9): Note! N2003: source conversion type is 'char const *const *'
x.c(9): Note! N2004: target conversion type is 'char **'
Okay this is the error, when I went through and cleaned up all the
warnings of passing (char **) as (const char **) parameters in other
compilers (gcc, MSVC), by converting function parameters to (char const
*const *), I STILL had warnings in watcom. This warning should please
to go away[engrish].
(though I still think that if the context is variable data passed to a
process expecting constant data, even if not all levels of indirection
are constant, it should be a compatible conversion, but am proven wrong
by C++ compilers)
----
Cut - ignore after this point.
Please do flog me if I dare misspell or mispunctuate.
In the beginning there is char, which is synonymous for purposes of this
conversation as byte, the plural of which is bytes.
All plural references may be assumed as preferably at least one, but
often more than one.
char c;
c is a variable character.
char const cc;
-or- const char cc;
c is a constant character.
char *s;
a variable pointer which points to a variable character;
char const *s;
-or- const char *s;
a variable pointer which points to a constant character.
char * const s;
A constant pointer which points to a variable character.
char const * const s;
-or- const char * const s;
a constant pointer which points to a constant character;
char * * l;
a variable pointer which points to a variable pointer which points to a
variable character.
char const * * l;
-or- const char * *l;
a variable pointer which points to a variable pointer which points to a
constant character.
char * const * l;
a variable pointer which points to a constant pointer which points to a
variable character;
char * * const l;
a constant pointer which points to a variable pointer which points to a
variable character;
char const * const * s;
-or- const char * const * s;
a variable pointer which points to a constant pointer which points to a
constant character.
char const * * const s;
-or- const char * * const s;
a constant pointer which points to a variable pointer which points to a
constant character.
char const * const * const s;
-or- const char * const * const s;
a constant pointer which points to a constant pointer which points to a
constant character.
One may assume that any code which requires a constant character may be
passed a variable character, with consideration that the implementation
is a single thread, and that the user of the constant data will
compelete before the data will be changed.
A more modern compiler might offer an option of declaring a variable
with volatile characteristics, such that the variable is assumed to be
able to change before a given process completes.
Most all modern compilers, and probably even lint processesors provide
no warning for converting a (char *) to a (const char *), that is if you
will recall, treating a variable character as a constant, immutable
character. Providing, even enforcing, that the process operating on the
data will not modify the data itself.
passing any such reference of non constant data to a constant data
process should not require a warning.
(const char **) = (char **) does not merit a warning, given that (const
char *) = (char *) does not.
-----------------
Some actual output from compilers - this is the program.
(Oops, this demonstrates the extra warnings in converting from (char **)
to (char const * const *)
---
int main( void )
{ char **a; // line (2)
const char *const* b; // line (3)
char *xa; // line (4)
const char *xb; // line (5)
int *xia; // line (6)
const int *xib; // line (7)
b = a; // line (8)
a = b; // line (9)
xa=xb; // line (10)
xb=xa; // line (11)
xia=xib; // line (12)
xib=xia; // line (13)
return 0; // line (14)
}
(msvc compiling as C)
[line](9) : error C2440: '=' : cannot convert from 'const char *const *
' to 'char ** '
Conversion loses qualifiers
[line](10) : error C2440: '=' : cannot convert from 'const char *' to
'char *'
Conversion loses qualifiers
[line](12) : error C2440: '=' : cannot convert from 'const int *' to
'int *'
Conversion loses qualifiers
(msvc compiling as C++)
m:\tmp\x.cpp(9) : error C2440: '=' : cannot convert from 'const char
*const * ' to 'char ** '
Conversion loses qualifiers
m:\tmp\x.cpp(10) : error C2440: '=' : cannot convert from 'const char *'
to 'char *'
Conversion loses qualifiers
m:\tmp\x.cpp(12) : error C2440: '=' : cannot convert from 'const int *'
to 'int *'
Conversion loses qualifiers
(gcc compiling as C)
x.c: In function 'main':
x.c:8: warning: assignment from incompatible pointer type
x.c:9: warning: assignment from incompatible pointer type
x.c:10: warning: assignment discards qualifiers from pointer target
type
x.c:12: warning: assignment discards qualifiers from pointer target
type
(g++ compiling as c++)
x.c: In function 'int main()':
x.c:9: error: invalid conversion from 'const char* const*' to 'char**'
x.c:10: error: invalid conversion from 'const char*' to 'char*'
x.c:12: error: invalid conversion from 'const int*' to 'int*'
(wcc386)
Open Watcom C32 Optimizing Compiler Version 1.5
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
x.c(8): Warning! W1178: Type qualifier mismatch
x.c(8): Note! N2003: source conversion type is 'char **'
x.c(8): Note! N2004: target conversion type is 'char const *const *'
x.c(9): Warning! W1178: Type qualifier mismatch
x.c(9): Note! N2003: source conversion type is 'char const *const *'
x.c(9): Note! N2004: target conversion type is 'char **'
x.c(10): Warning! W1178: Type qualifier mismatch
x.c(10): Note! N2003: source conversion type is 'char const *'
x.c(10): Note! N2004: target conversion type is 'char *'
x.c(12): Warning! W1178: Type qualifier mismatch
x.c(12): Note! N2003: source conversion type is 'int const *'
x.c(12): Note! N2004: target conversion type is 'int *'
x.c: 15 lines, 4 warnings, 0 errors
(wpp386)
M:\tmp>wpp386 x.c
Open Watcom C++32 Optimizing Compiler Version 1.5
Portions Copyright (c) 1989-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
x.c(9): Error! E246: col(3) left expression is not a pointer to a
constant object
x.c(9): Note! N717: col(3) left operand type is 'char * * (lvalue)'
x.c(9): Note! N718: col(3) right operand type is 'char const * const *'
x.c(10): Error! E246: col(3) left expression is not a pointer to a
constant object
x.c(10): Note! N717: col(3) left operand type is 'char * (lvalue)'
x.c(10): Note! N718: col(3) right operand type is 'char const *'
x.c(12): Error! E246: col(4) left expression is not a pointer to a
constant object
x.c(12): Note! N717: col(4) left operand type is 'int * (lvalue)'
x.c(12): Note! N718: col(4) right operand type is 'int const *'
x.c: 15 lines, no warnings, 3 errors
------
So in conclusion,
line 8 is not a warning or error in any C++ compiler.
nor ls 11 or 13;
-----------------------------------------------
---- section 2 ----
------
x.c
int main( void )
{
char **a;
char const *const *b;
b = a; // line(9)
}
------
wpp386 x.c
x.c(9): Warning! W1178: Type qualifier mismatch
x.c(9): Note! N2003: source conversion type is 'char const *const *'
x.c(9): Note! N2004: target conversion type is 'char **'
Okay this is the error, when I went through and cleaned up all the
warnings of passing (char **) as (const char **) parameters in other
compilers (gcc, MSVC), by converting function parameters to (char const
*const *), I STILL had warnings in watcom. This warning should please
to go away[engrish].
(though I still think that if the context is variable data passed to a
process expecting constant data, even if not all levels of indirection
are constant, it should be a compatible conversion, but am proven wrong
by C++ compilers)
----
Cut - ignore after this point.
Please do flog me if I dare misspell or mispunctuate.
In the beginning there is char, which is synonymous for purposes of this
conversation as byte, the plural of which is bytes.
All plural references may be assumed as preferably at least one, but
often more than one.
char c;
c is a variable character.
char const cc;
-or- const char cc;
c is a constant character.
char *s;
a variable pointer which points to a variable character;
char const *s;
-or- const char *s;
a variable pointer which points to a constant character.
char * const s;
A constant pointer which points to a variable character.
char const * const s;
-or- const char * const s;
a constant pointer which points to a constant character;
char * * l;
a variable pointer which points to a variable pointer which points to a
variable character.
char const * * l;
-or- const char * *l;
a variable pointer which points to a variable pointer which points to a
constant character.
char * const * l;
a variable pointer which points to a constant pointer which points to a
variable character;
char * * const l;
a constant pointer which points to a variable pointer which points to a
variable character;
char const * const * s;
-or- const char * const * s;
a variable pointer which points to a constant pointer which points to a
constant character.
char const * * const s;
-or- const char * * const s;
a constant pointer which points to a variable pointer which points to a
constant character.
char const * const * const s;
-or- const char * const * const s;
a constant pointer which points to a constant pointer which points to a
constant character.
One may assume that any code which requires a constant character may be
passed a variable character, with consideration that the implementation
is a single thread, and that the user of the constant data will
compelete before the data will be changed.
A more modern compiler might offer an option of declaring a variable
with volatile characteristics, such that the variable is assumed to be
able to change before a given process completes.
Most all modern compilers, and probably even lint processesors provide
no warning for converting a (char *) to a (const char *), that is if you
will recall, treating a variable character as a constant, immutable
character. Providing, even enforcing, that the process operating on the
data will not modify the data itself.
passing any such reference of non constant data to a constant data
process should not require a warning.
(const char **) = (char **) does not merit a warning, given that (const
char *) = (char *) does not.
-----------------
Some actual output from compilers - this is the program.
(Oops, this demonstrates the extra warnings in converting from (char **)
to (char const * const *)
---
int main( void )
{ char **a; // line (2)
const char *const* b; // line (3)
char *xa; // line (4)
const char *xb; // line (5)
int *xia; // line (6)
const int *xib; // line (7)
b = a; // line (8)
a = b; // line (9)
xa=xb; // line (10)
xb=xa; // line (11)
xia=xib; // line (12)
xib=xia; // line (13)
return 0; // line (14)
}
(msvc compiling as C)
[line](9) : error C2440: '=' : cannot convert from 'const char *const *
' to 'char ** '
Conversion loses qualifiers
[line](10) : error C2440: '=' : cannot convert from 'const char *' to
'char *'
Conversion loses qualifiers
[line](12) : error C2440: '=' : cannot convert from 'const int *' to
'int *'
Conversion loses qualifiers
(msvc compiling as C++)
m:\tmp\x.cpp(9) : error C2440: '=' : cannot convert from 'const char
*const * ' to 'char ** '
Conversion loses qualifiers
m:\tmp\x.cpp(10) : error C2440: '=' : cannot convert from 'const char *'
to 'char *'
Conversion loses qualifiers
m:\tmp\x.cpp(12) : error C2440: '=' : cannot convert from 'const int *'
to 'int *'
Conversion loses qualifiers
(gcc compiling as C)
x.c: In function 'main':
x.c:8: warning: assignment from incompatible pointer type
x.c:9: warning: assignment from incompatible pointer type
x.c:10: warning: assignment discards qualifiers from pointer target
type
x.c:12: warning: assignment discards qualifiers from pointer target
type
(g++ compiling as c++)
x.c: In function 'int main()':
x.c:9: error: invalid conversion from 'const char* const*' to 'char**'
x.c:10: error: invalid conversion from 'const char*' to 'char*'
x.c:12: error: invalid conversion from 'const int*' to 'int*'
(wcc386)
Open Watcom C32 Optimizing Compiler Version 1.5
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
x.c(8): Warning! W1178: Type qualifier mismatch
x.c(8): Note! N2003: source conversion type is 'char **'
x.c(8): Note! N2004: target conversion type is 'char const *const *'
x.c(9): Warning! W1178: Type qualifier mismatch
x.c(9): Note! N2003: source conversion type is 'char const *const *'
x.c(9): Note! N2004: target conversion type is 'char **'
x.c(10): Warning! W1178: Type qualifier mismatch
x.c(10): Note! N2003: source conversion type is 'char const *'
x.c(10): Note! N2004: target conversion type is 'char *'
x.c(12): Warning! W1178: Type qualifier mismatch
x.c(12): Note! N2003: source conversion type is 'int const *'
x.c(12): Note! N2004: target conversion type is 'int *'
x.c: 15 lines, 4 warnings, 0 errors
(wpp386)
M:\tmp>wpp386 x.c
Open Watcom C++32 Optimizing Compiler Version 1.5
Portions Copyright (c) 1989-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
x.c(9): Error! E246: col(3) left expression is not a pointer to a
constant object
x.c(9): Note! N717: col(3) left operand type is 'char * * (lvalue)'
x.c(9): Note! N718: col(3) right operand type is 'char const * const *'
x.c(10): Error! E246: col(3) left expression is not a pointer to a
constant object
x.c(10): Note! N717: col(3) left operand type is 'char * (lvalue)'
x.c(10): Note! N718: col(3) right operand type is 'char const *'
x.c(12): Error! E246: col(4) left expression is not a pointer to a
constant object
x.c(12): Note! N717: col(4) left operand type is 'int * (lvalue)'
x.c(12): Note! N718: col(4) right operand type is 'int const *'
x.c: 15 lines, no warnings, 3 errors
------
So in conclusion,
line 8 is not a warning or error in any C++ compiler.
nor ls 11 or 13;
-----------------------------------------------
---- section 2 ----