Mark McIntyre <
[email protected]> scribbled the following
on comp.lang.c:
(snip pretty contrived example of difference between C and C+ compiler)
I don't understand. Although the C standard says that the type char[2]
is assignable to the type char *, it also says that the type char[2][2]
is definitely *not* assignable to the type char **.
Yeah, maybe. But no C compiler I've encountered will reject this code,
while every C++ one will. Like I said, QOI, or what? I belive you're right,
but the fact is, C code that compiles /and runs just fine on multiple
implementations/ won't even compile under C++.
Note the MODEs lines:
G:\tmp>como fooa.cpp
Comeau C/C++ 4.3.4.1 (Sep 19 2004 11:33:48) for MS_WINDOWS_x86
Copyright 1988-2004 Comeau Computing. All rights reserved.
MODE:non-strict warnings microsoft C++
"fooa.cpp", line 10: error: argument of type "char **" is incompatible with
parameter of type "char (*)[2]"
foo(a);
^
"fooa.cpp", line 10: warning: variable "a" is used before its value is set
foo(a);
^
1 error detected in the compilation of "fooa.cpp".
G:\tmp>como --A fooa.cpp
Comeau C/C++ 4.3.4.1 (Sep 19 2004 11:33:48) for MS_WINDOWS_x86
Copyright 1988-2004 Comeau Computing. All rights reserved.
MODE:strict errors C++
"fooa.cpp", line 10: error: argument of type "char **" is incompatible with
parameter of type "char (*)[2]"
foo(a);
^
"fooa.cpp", line 10: warning: variable "a" is used before its value is set
foo(a);
^
1 error detected in the compilation of "fooa.cpp".
"fooa.cpp", line 10: error: argument of type "char **" is incompatible with
parameter of type "char (*)[2]"
foo(a);
^
"fooa.cpp", line 10: warning: variable "a" is used before its value is set
foo(a);
^
1 error detected in the compilation of "fooa.cpp".
G:\tmp>como --c fooa.cpp
Comeau C/C++ 4.3.4.1 (Sep 19 2004 11:33:48) for MS_WINDOWS_x86
Copyright 1988-2004 Comeau Computing. All rights reserved.
MODE:non-strict warnings microsoft C90
"fooa.cpp", line 10: warning: argument of type "char **" is incompatible with
parameter of type "char (*)[2]"
foo(a);
^
"fooa.cpp", line 10: warning: variable "a" is used before its value is set
foo(a);
^
G:\tmp>como --c --A fooa.cpp
Comeau C/C++ 4.3.4.1 (Sep 19 2004 11:33:48) for MS_WINDOWS_x86
Copyright 1988-2004 Comeau Computing. All rights reserved.
MODE:strict errors C90
"fooa.cpp", line 2: error: expected an expression
// do nothing
^
"fooa.cpp", line 5: warning: parsing restarts here after previous syntax error
}
^
"fooa.cpp", line 5: error: expected a ";"
}
^
"fooa.cpp", line 10: error: argument of type "char **" is incompatible with
parameter of type "char (*)[2]"
foo(a);
^
"fooa.cpp", line 10: warning: variable "a" is used before its value is set
foo(a);
^
3 errors detected in the compilation of "fooa.cpp".
G:\tmp>como --c99 fooa.cpp
Comeau C/C++ 4.3.4.1 (Sep 19 2004 11:33:48) for MS_WINDOWS_x86
Copyright 1988-2004 Comeau Computing. All rights reserved.
MODE:non-strict warnings microsoft C99
"fooa.cpp", line 10: warning: argument of type "char **" is incompatible with
parameter of type "char (*)[2]"
foo(a);
^
"fooa.cpp", line 10: warning: variable "a" is used before its value is set
foo(a);
^
G:\tmp>como --c99 --A fooa.cpp
Comeau C/C++ 4.3.4.1 (Sep 19 2004 11:33:48) for MS_WINDOWS_x86
Copyright 1988-2004 Comeau Computing. All rights reserved.
MODE:strict errors C99
"fooa.cpp", line 10: error: argument of type "char **" is incompatible with
parameter of type "char (*)[2]"
foo(a);
^
"fooa.cpp", line 10: warning: variable "a" is used before its value is set
foo(a);
^
1 error detected in the compilation of "fooa.cpp".
I can't imagine any other C++ or C compiler acting differently in
their strict modes too, at least to not even put out a warning.