gcc me harder: -Wconversion bug?

2003-06-09 Thread Sean Chittenden
[ Please CC: me on replies, not on questions@ ]

Is this a GCC bug with the -Wconversion flag or am I doing something
wrong?  I know it's just a warning, but it's irritating me more than
that dumb Dan Quayle quote, "if it weren't for that horse, I wouldn't
have spent an extra year in college..."  -sc

% gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.2.2 [FreeBSD] 20030205 (release)
% uname -a
FreeBSD hostname.example.com 5.1-CURRENT FreeBSD 5.1-CURRENT #2: Mon Jun  9 12:23:34 
PDT 2003 [EMAIL PROTECTED]:/usr/src/sys/i386/compile/HOSTNAME  i386


% gcc -Wconversion test.c
test.c: In function `main':
test.c:5: warning: passing arg 1 of `f' with different width due to prototype

/* Begin test.h */
#ifndef __TEST_H__
#define __TEST_H__

#ifndef bool
typedef char bool;
#endif

#ifndef true
#define true((bool)1)
#endif

#ifndef false
#define false   ((bool)0)
#endif

void f(bool b);
#endif
/* End test.h */


/* Begin test.c */
#include "test.h"

int
main(void) {
  f(true);
  return(0);
}

void
f(bool b) { }
/* End test.c */

-- 
Sean Chittenden
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: gcc me harder: -Wconversion bug?

2003-06-10 Thread Malcolm Kay
On Tue, 10 Jun 2003 08:33, Sean Chittenden wrote:
> [ Please CC: me on replies, not on questions@ ]
>
> Is this a GCC bug with the -Wconversion flag or am I doing something
> wrong?  I know it's just a warning, but it's irritating me more than
> that dumb Dan Quayle quote, "if it weren't for that horse, I wouldn't
> have spent an extra year in college..."  -sc
>
> % gcc -v
> Using built-in specs.
> Configured with: FreeBSD/i386 system compiler
> Thread model: posix
> gcc version 3.2.2 [FreeBSD] 20030205 (release)
> % uname -a
> FreeBSD hostname.example.com 5.1-CURRENT FreeBSD 5.1-CURRENT #2: Mon Jun  9
> 12:23:34 PDT 2003
> [EMAIL PROTECTED]:/usr/src/sys/i386/compile/HOSTNAME  i386
>
>
> % gcc -Wconversion test.c
> test.c: In function `main':
> test.c:5: warning: passing arg 1 of `f' with different width due to
> prototype
>
> /* Begin test.h */
> #ifndef __TEST_H__
> #define __TEST_H__
>
> #ifndef bool
> typedef char bool;
> #endif
>
> #ifndef true
> #define true((bool)1)
> #endif
>
> #ifndef false
> #define false   ((bool)0)
> #endif
>
> void f(bool b);
> #endif
> /* End test.h */
>
>
> /* Begin test.c */
> #include "test.h"
>
> int
> main(void) {
>   f(true);
>   return(0);
> }
>
> void
> f(bool b) { }
> /* End test.c */

It seems to me that this is doing exactly what is claimed for -Wconversion.
To quote from the gcc man page:
   -Wconversion
  Warn  if  a prototype causes a type conversion that
  is different from what would happen to the same ar-
  gument  in  the  absence  of a prototype.  ...

Now in the absence of a prototype for f() the argument true would be promoted 
from char/bool to int before being passed to the function. With the prototype
in scope it is not promoted. Different argument widths so warning delivered.

Malcolm
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: gcc me harder: -Wconversion bug?

2003-06-10 Thread Sean Chittenden
> It seems to me that this is doing exactly what is claimed for -Wconversion.
> To quote from the gcc man page:
>-Wconversion
>   Warn  if  a prototype causes a type conversion that
>   is different from what would happen to the same ar-
>   gument  in  the  absence  of a prototype.  ...
> 
> Now in the absence of a prototype for f() the argument true would be
> promoted from char/bool to int before being passed to the
> function. With the prototype in scope it is not promoted. Different
> argument widths so warning delivered.

% cpp test.c
# 1 "test7.c"
# 1 ""
# 1 ""
# 1 "test7.c"
# 1 "test7.h" 1
# 13 "test7.h"
void f(char b);
# 2 "test7.c" 2

int
main(int argc, char *argv[]) {
  fchar)1)));

  return(0);
}

void
f(char b) {
}

Am I missing something that says that there isn't the prototype of the
same width?  Last time I checked my vision, f(char b) was the same as
f(char b)...  :-/ or am I missing something?  I believe that gcc's
promoting the char to an int or to some other non-1 byte width data
type... but I'm not seeing how, where, or why.  -sc

-- 
Sean Chittenden
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: gcc me harder: -Wconversion bug?

2003-06-10 Thread Malcolm Kay
On Tue, 10 Jun 2003 18:51, Sean Chittenden wrote:
> > It seems to me that this is doing exactly what is claimed for
> > -Wconversion. To quote from the gcc man page:
> >-Wconversion
> >   Warn  if  a prototype causes a type conversion that
> >   is different from what would happen to the same ar-
> >   gument  in  the  absence  of a prototype.  ...
> >
> > Now in the absence of a prototype for f() the argument true would be
> > promoted from char/bool to int before being passed to the
> > function. With the prototype in scope it is not promoted. Different
> > argument widths so warning delivered.
>
> % cpp test.c
> # 1 "test7.c"
> # 1 ""
> # 1 ""
> # 1 "test7.c"
> # 1 "test7.h" 1
> # 13 "test7.h"
> void f(char b);
> # 2 "test7.c" 2
>
> int
> main(int argc, char *argv[]) {
>   fchar)1)));
>
>   return(0);
> }
>
> void
> f(char b) {
> }
>
> Am I missing something that says that there isn't the prototype of the
> same width?  Last time I checked my vision, f(char b) was the same as
> f(char b)...  :-/ or am I missing something?  I believe that gcc's
> promoting the char to an int or to some other non-1 byte width data
> type... but I'm not seeing how, where, or why.  -sc

According to the man page we are comaring what does happen with
the prototype in scope with what would have happened if the prototype 
was not there.

You are aware theat the rules of C require that in the absence of a prototype
actual integer calling arguments of less width than int (usually char and 
short) must be promoted to int before the call?

Malcolm

___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: gcc me harder: -Wconversion bug?

2003-06-10 Thread Sean Chittenden
> > > It seems to me that this is doing exactly what is claimed for
> > > -Wconversion. To quote from the gcc man page:
> > >-Wconversion
> > >   Warn  if  a prototype causes a type conversion that
> > >   is different from what would happen to the same ar-
> > >   gument  in  the  absence  of a prototype.  ...
> > >
> > > Now in the absence of a prototype for f() the argument true would be
> > > promoted from char/bool to int before being passed to the
> > > function. With the prototype in scope it is not promoted. Different
> > > argument widths so warning delivered.
> >
> > % cpp test.c
> > # 1 "test7.c"
> > # 1 ""
> > # 1 ""
> > # 1 "test7.c"
> > # 1 "test7.h" 1
> > # 13 "test7.h"
> > void f(char b);
> > # 2 "test7.c" 2
> >
> > int
> > main(int argc, char *argv[]) {
> >   fchar)1)));
> >
> >   return(0);
> > }
> >
> > void
> > f(char b) {
> > }
> >
> > Am I missing something that says that there isn't the prototype of
> > the same width?  Last time I checked my vision, f(char b) was the
> > same as f(char b)...  :-/ or am I missing something?  I believe
> > that gcc's promoting the char to an int or to some other non-1
> > byte width data type... but I'm not seeing how, where, or why.
> > -sc
> 
> According to the man page we are comaring what does happen with the
> prototype in scope with what would have happened if the prototype
> was not there.
> 
> You are aware theat the rules of C require that in the absence of a
> prototype actual integer calling arguments of less width than int
> (usually char and short) must be promoted to int before the call?

Wow, that's a really worthless warning.  I had to re-read it in the AM
to fully appreciate its non-usefulness for properly written software.
Thanks... when reading the error message and skimming the man page, I
thought it was promoting width of the argument to 4 bytes, not that
"in the event that the prototype isn't here, things will get hard to
debug."  Thank you, for your incite.  -sc

-- 
Sean Chittenden
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"


Re: gcc me harder: -Wconversion bug?

2003-06-10 Thread Malcolm Kay
On Wed, 11 Jun 2003 05:30, Sean Chittenden wrote:
> > > > It seems to me that this is doing exactly what is claimed for
> > > > -Wconversion. To quote from the gcc man page:
> > > >-Wconversion
> > > >   Warn  if  a prototype causes a type conversion that
> > > >   is different from what would happen to the same ar-
> > > >   gument  in  the  absence  of a prototype.  ...
> > > >
> > > > Now in the absence of a prototype for f() the argument true would be
> > > > promoted from char/bool to int before being passed to the
> > > > function. With the prototype in scope it is not promoted. Different
> > > > argument widths so warning delivered.
> > >
> > > % cpp test.c
> > > # 1 "test7.c"
> > > # 1 ""
> > > # 1 ""
> > > # 1 "test7.c"
> > > # 1 "test7.h" 1
> > > # 13 "test7.h"
> > > void f(char b);
> > > # 2 "test7.c" 2
> > >
> > > int
> > > main(int argc, char *argv[]) {
> > >   fchar)1)));
> > >
> > >   return(0);
> > > }
> > >
> > > void
> > > f(char b) {
> > > }
> > >
> > > Am I missing something that says that there isn't the prototype of
> > > the same width?  Last time I checked my vision, f(char b) was the
> > > same as f(char b)...  :-/ or am I missing something?  I believe
> > > that gcc's promoting the char to an int or to some other non-1
> > > byte width data type... but I'm not seeing how, where, or why.
> > > -sc
> >
> > According to the man page we are comaring what does happen with the
> > prototype in scope with what would have happened if the prototype
> > was not there.
> >
> > You are aware theat the rules of C require that in the absence of a
> > prototype actual integer calling arguments of less width than int
> > (usually char and short) must be promoted to int before the call?
>
> Wow, that's a really worthless warning.  I had to re-read it in the AM
> to fully appreciate its non-usefulness for properly written software.
> Thanks... when reading the error message and skimming the man page, I
> thought it was promoting width of the argument to 4 bytes, not that
> "in the event that the prototype isn't here, things will get hard to
> debug."  Thank you, for your incite.  -sc

Gcc has many warning options and quite a few would be classified as not
applicable for general use (but might be useful to someone carrying on a 
particular investigation). This particular one is not, to my knowledge,
included in any of the catchalls such as -Wall or -W.

Malcolm
___
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"