This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Warning C vs C++
- From: Vassili Karpov <vassili dot karpov at iss dot ru>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 17 Sep 2005 16:13:16 +0400
- Subject: Warning C vs C++
Hello,
Consider following snippet:
#include <string.h>
int main (int argc, char *argv[])
{
char *s1 = argv[0];
char *s2 = strchr (s1, '/');
char r;
(void) argc;
r = s2 ? (s2 - s1) : strlen (s1);
return 0;
}
And the results of compilation:
cvscxx$ gcc-4.0.0 -Wall -Werror -c cvscxx.c && echo Success
Success
cvscxx$ gcc-4.0.0 -Wall -Werror -W -c cvscxx.c && echo Success
cc1: warnings being treated as errors
cvscxx.c: In function 'main':
cvscxx.c:11: warning: signed and unsigned type in conditional expression
cvscxx$ g++-4.0.0 -Wall -Werror -W -c cvscxx.c && echo Success
Success
Questions:
a. Why it does not err on just -Wall?
b. Why is error message with -W what it is? instead of something like
what microsoft's compiler produces:
cl /Wall /c cvscxx.c
cvscxx.c(11) : warning C4244: '=' : conversion from 'size_t' to 'unsigned
char', possible loss of data
c. Why when compiled with C++ compiler there is no warning at all even with
-W (or even -Wextra)?
d. What is actual type of the ?: expression? ptrdiff_t? size_t?