unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* warning compiling dbusbind.c
@ 2008-01-24 19:18 Glenn Morris
  2008-01-24 20:05 ` Michael Albinus
  0 siblings, 1 reply; 8+ messages in thread
From: Glenn Morris @ 2008-01-24 19:18 UTC (permalink / raw)
  To: michael.albinus; +Cc: emacs-devel


I receive this warning compiling dbusbind.c on x86_64 GNU/Linux with
gcc 4.1:

dbusbind.c: In function 'xd_retrieve_arg':
dbusbind.c:600: warning: comparison is always false due to limited
range of data type

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: warning compiling dbusbind.c
  2008-01-24 19:18 warning compiling dbusbind.c Glenn Morris
@ 2008-01-24 20:05 ` Michael Albinus
  2008-01-24 21:25   ` Stefan Monnier
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Albinus @ 2008-01-24 20:05 UTC (permalink / raw)
  To: Glenn Morris; +Cc: emacs-devel

Glenn Morris <rgm@gnu.org> writes:

> I receive this warning compiling dbusbind.c on x86_64 GNU/Linux with
> gcc 4.1:
>
> dbusbind.c: In function 'xd_retrieve_arg':
> dbusbind.c:600: warning: comparison is always false due to limited
> range of data type

The code in question is

	dbus_uint32_t val;
	dbus_message_iter_get_basic (iter, &val);
	XD_DEBUG_MESSAGE ("%c %d", dtype, val);
	return make_fixnum_or_float (val);

I've used make_fixnum_or_float, because BITS_PER_EMACS_INT is too small
on 32bit machines. One possible solution could be

	dbus_uint32_t val;
	dbus_message_iter_get_basic (iter, &val);
	XD_DEBUG_MESSAGE ("%c %d", dtype, val);
#if BITS_PER_EMACS_INT >= 32
	return make_number (val);
#else
	return make_fixnum_or_float (val);
#endif

On the other hand, shouldn't it be handled in make_fixnum_or_float?

Best regards, Michael.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: warning compiling dbusbind.c
  2008-01-24 20:05 ` Michael Albinus
@ 2008-01-24 21:25   ` Stefan Monnier
  2008-01-24 22:33     ` Glenn Morris
  0 siblings, 1 reply; 8+ messages in thread
From: Stefan Monnier @ 2008-01-24 21:25 UTC (permalink / raw)
  To: Michael Albinus; +Cc: Glenn Morris, emacs-devel

> I've used make_fixnum_or_float, because BITS_PER_EMACS_INT is too small
> on 32bit machines. One possible solution could be

> 	dbus_uint32_t val;
> 	dbus_message_iter_get_basic (iter, &val);
> 	XD_DEBUG_MESSAGE ("%c %d", dtype, val);
> #if BITS_PER_EMACS_INT >= 32
> 	return make_number (val);
> #else
> 	return make_fixnum_or_float (val);
> #endif

Yuck.  I must prefer living with the warning (which is just that:
a warning.  We already have several similar ones).

> On the other hand, shouldn't it be handled in make_fixnum_or_float?

No, because make_fixnum_or_float expects an integer of type EMACS_INT.
The problem here is that you pass it an object that is slight smaller,
so soome of its internal code cann be optimized away, which is what the
compiler warns you about.  Maybe casting val to EMACS_INT is enough to
silence the compiler?

I wonder if gcc would also complain  in the case where
make_fixnum_or_float is an inlinable function.  I'd guess not.


        Stefan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: warning compiling dbusbind.c
  2008-01-24 21:25   ` Stefan Monnier
@ 2008-01-24 22:33     ` Glenn Morris
  2008-01-24 23:20       ` Nick Roberts
  2008-01-25 19:04       ` Michael Albinus
  0 siblings, 2 replies; 8+ messages in thread
From: Glenn Morris @ 2008-01-24 22:33 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Michael Albinus, emacs-devel

Stefan Monnier wrote:

> Yuck.  I must prefer living with the warning (which is just that:
> a warning.  We already have several similar ones).

I menioned this because it is the only warning of any kind I get when
compiling the Emacs C code.

(There are a few instances of workarounds for this in the C code
already: `grep whining src/*.c' .)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: warning compiling dbusbind.c
  2008-01-24 22:33     ` Glenn Morris
@ 2008-01-24 23:20       ` Nick Roberts
  2008-01-25  2:19         ` Stefan Monnier
  2008-01-25 19:04       ` Michael Albinus
  1 sibling, 1 reply; 8+ messages in thread
From: Nick Roberts @ 2008-01-24 23:20 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Michael Albinus, Stefan Monnier, emacs-devel

 > > Yuck.  I must prefer living with the warning (which is just that:
 > > a warning.  We already have several similar ones).
 > 
 > I menioned this because it is the only warning of any kind I get when
 > compiling the Emacs C code.

Indeed, in GDB all files are compiled with the -Werror option, presumably
because GCC folks are more knowledgeable about what is undesirable than the
average developer.

-- 
Nick                                           http://www.inet.net.nz/~nickrob

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: warning compiling dbusbind.c
  2008-01-24 23:20       ` Nick Roberts
@ 2008-01-25  2:19         ` Stefan Monnier
  0 siblings, 0 replies; 8+ messages in thread
From: Stefan Monnier @ 2008-01-25  2:19 UTC (permalink / raw)
  To: Nick Roberts; +Cc: Glenn Morris, Michael Albinus, emacs-devel

>> > Yuck.  I must prefer living with the warning (which is just that:
>> > a warning.  We already have several similar ones).
>> 
>> I menioned this because it is the only warning of any kind I get when
>> compiling the Emacs C code.

> Indeed, in GDB all files are compiled with the -Werror option, presumably
> because GCC folks are more knowledgeable about what is undesirable than the
> average developer.

But uglifying the code and making it less maintainable just to get rid
of a minor warning is not good software engineering practices.

I'd much rather introduce a dummy macro like

    #define DEFEAT_WARNING(x) ((EMACS_INT)(x))

or even

    #define DEFEAT_WARNING(x) ((((EMACS_INT)(x))+1)-1)

then introduce the "#if BITS_PER_EMACS_INT >= 32" that dispatches to two
different macros, where the reason why it's correct is not nearly
as obvious.


        Stefan

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: warning compiling dbusbind.c
  2008-01-24 22:33     ` Glenn Morris
  2008-01-24 23:20       ` Nick Roberts
@ 2008-01-25 19:04       ` Michael Albinus
  2008-01-25 22:42         ` Glenn Morris
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Albinus @ 2008-01-25 19:04 UTC (permalink / raw)
  To: Glenn Morris; +Cc: Stefan Monnier, emacs-devel

Glenn Morris <rgm@gnu.org> writes:

> I menioned this because it is the only warning of any kind I get when
> compiling the Emacs C code.
>
> (There are a few instances of workarounds for this in the C code
> already: `grep whining src/*.c' .)

Thanks for the pointer, I've fixed it this way. When there is a macro,
as Stefan has proposed, it could be introduced for all these cases at
once.

Could you, please, check on your machine? I haven't a 64bit one.

Best regards, Michael.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: warning compiling dbusbind.c
  2008-01-25 19:04       ` Michael Albinus
@ 2008-01-25 22:42         ` Glenn Morris
  0 siblings, 0 replies; 8+ messages in thread
From: Glenn Morris @ 2008-01-25 22:42 UTC (permalink / raw)
  To: Michael Albinus; +Cc: Stefan Monnier, emacs-devel

Michael Albinus wrote:

> Thanks for the pointer, I've fixed it this way. When there is a macro,
> as Stefan has proposed, it could be introduced for all these cases at
> once.
>
> Could you, please, check on your machine? I haven't a 64bit one.

No more compilation warning; thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-01-25 22:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-24 19:18 warning compiling dbusbind.c Glenn Morris
2008-01-24 20:05 ` Michael Albinus
2008-01-24 21:25   ` Stefan Monnier
2008-01-24 22:33     ` Glenn Morris
2008-01-24 23:20       ` Nick Roberts
2008-01-25  2:19         ` Stefan Monnier
2008-01-25 19:04       ` Michael Albinus
2008-01-25 22:42         ` Glenn Morris

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).