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]

-Wconversion ignores type casts



$ uname -a
Linux vsl01 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown

$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)


The "-Wconversion" warning option seems to ignore explicit type casts
on function arguments.  I'm attaching a small C source file that
demonstrates the problem.

--

Ted Hall
Department of Architecture
Chinese University of Hong Kong
Sha Tin, HONG KONG
/*
 * File:
 *
 *    chararg.c
 *
 * System:
 *
 *    $ uname -a
 *    Linux vsl01 2.2.12-20 #1 Mon Sep 27 10:40:35 EDT 1999 i686 unknown
 *
 *    $ gcc -v
 *    Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
 *    gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
 *
 * Summary:
 *
 *    gcc -x c -Wconversion -o chararg chararg.c
 *
 *    Compiling this program with -Wconversion produces the following
 *    inappropriate warnings:
 *
 * warning: passing arg 1 of `ufunc' with different width due to prototype
 * warning: passing arg 1 of `sfunc' with different width due to prototype
 * warning: passing arg 1 of `rfunc' with different width due to prototype
 *
 *    This happens whether the prototypes and args are char or short, but not
 *    for int or long.  The warning seems to ignore the explicit type cast in
 *    the call to the function.
 */

#include <stdlib.h>
#include <stdio.h>

   void ufunc (unsigned char v) ;
   void sfunc (signed char   v) ;
   void rfunc (char          v) ;

   int main (void)
   {
      ufunc ((unsigned char) 'U') ;
      sfunc ((signed char)   'S') ;
      rfunc ((char)          'R') ;
      return (EXIT_SUCCESS) ;
   }

   void ufunc (unsigned char v)
   {
      fprintf (stdout, "unsigned %c\n", v) ;
   }

   void sfunc (signed char v)
   {
      fprintf (stdout, "signed   %c\n", v) ;
   }

   void rfunc (char v)
   {
      fprintf (stdout, "regular  %c\n", v) ;
   }

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