On Sat, 24 Jul 2010, Denys Vlasenko wrote:
> On Saturday 24 July 2010 01:03, Cristian Ionescu-Idbohrn wrote:
> > When using this compiler option:
> >
> > CFLAGS += -Wbad-function-cast
>
> Why?
Just because I can :)
Would it be better to not generate or ignore the warnings?
On a 32 bit x86, going from double to unsigned is going from 8 bytes to 4
bytes, isn't it?
> I googled for the rationale why this warning is useful,
> but came up empty.
Yes, it's not often but not unusual that gcc option is used.
`-Wbad-function-cast'
Warn whenever a function call is cast to a non-matching type. For
example, warn if `int malloc()' is cast to `anything *'.
> > I see several warnings (as in Subject:) while compiling miscutils/dc.c.
> > One of them in function 'mod'. Applying this patch:
> >
> > diff --git a/miscutils/dc.c b/miscutils/dc.c
> > index cb4b1e9..f9b8ab2 100644
> > --- a/miscutils/dc.c
> > +++ b/miscutils/dc.c
> > @@ -74,8 +74,9 @@ static void divide(void)
> > static void mod(void)
> > {
> > unsigned d = pop();
> > + unsigned c = pop();
> >
> > - push((unsigned) pop() % d);
> > + push(c % d);
> > }
> >
> > static void and(void)
> >
> > makes that warning go away, but bloats the result by a few bytes.
> > What do people think? Shall we blame gcc again for stupidity?
It's just a question. I'm puzzled. Given pop is:
static double pop(void)
{
if (pointer == 0)
bb_error_msg_and_die("stack underflow");
return stack[--pointer];
}
Why is this:
static void mod(void)
{
unsigned d = pop();
push((unsigned) pop() % d);
}
generating the warning, but not this:
static void mod(void)
{
unsigned d = pop();
unsigned c = pop();
push(c % d);
}
> With this gcc:
>
> $ i686-gcc -v
> Invoked as i686-gcc
> Reference path: /.share/usr/app/fwl_uclibc_i686-0.9.11/bin/..
> arg[ 0] = rawcc
> arg[ 1] = -U__nptl__
> arg[ 2] = -v
> Using built-in specs.
> Target: i686-unknown-linux
> Configured with: /2bogus/build/temp-i686/gcc-core/configure
> --target=i686-unknown-linux --prefix=/2bogus/build/native-compiler-i686
> --disable-multilib --disable-nls --enable-c99 --enable-long-long
> --enable-__cxa_atexit --enable-languages=c,c++ --disable-libstdcxx-pch
> --program-prefix= --enable-threads=posix --enable-shared
> --build=x86_64-walrus-linux --host=i686-unknown-linux --enable-sjlj-exceptions
> Thread model: posix
> gcc version 4.2.1
With this gcc:
$ gcc -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.4.4-7'
--with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--enable-shared --enable-multiarch --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4
--program-suffix=-4.4 --enable-nls --enable-clocale=gnu
--enable-libstdcxx-debug --enable-objc-gc --enable-targets=all
--with-arch-32=i586 --with-tune=generic --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.4.4 (Debian 4.4.4-7)
> I am getting no code difference.
I do.
Cheers,
--
Cristian
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox