This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]