🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1483

Is This Sailing A Little Close To The Wind?

#1483
From: Lawrence D’Oliveiro
Date: Thu, 12 Nov 2026 06:59
42 lines
2762 bytes
An interesting report was recently posted on comp.emacs about some
compiler warnings flagged when building Emacs. Here’s an example (the
others are somewhat similar):

    /usr/opt/Emacs-31.1/emacs-31.1/src/fileio.c:3960:31: warning: implicit
           conversion from 'off_t' (aka 'long long') to 'double' changes value
    from
           9223372036854775807 to 9223372036854775808
           [-Wimplicit-const-int-float-conversion]

The above (according to the Emacs 30.2 sources I happen to have handy)
is in a C function called “file_offset”, clearly meant to be called
from Lisp (it takes a “Lisp_Object” argument), which expects a numeric
argument and converts it to an off_t. It accepts either a Lisp integer
or float object, and converts it accordingly. Here’s the part that
converts a float:

  else if (FLOATP (val))
    {
      double v = XFLOAT_DATA (val);
      if (0 <= v && v < 1.0 + TYPE_MAXIMUM (off_t))
	{
	  off_t o = v;
	  if (o == v)
	    return o;
	}
    }

Now, for 64-bit off_t (the usual state of affairs these days), the
TYPE_MAXIMUM macro returns 9223372036854775807. Converting that to
double, it gets rounded to 9223372036854775808. And then the addition
of 1.0 ... gets lost in the rounding, so the result is still
9223372036854775808, which is what the addition of 1.0 was supposed to
produce in the first place.

In other words, the limit check still works!

I would feel pretty nervous writing code like this. At the very least,
I would add an explanatory comment detailing what is going on. Or
maybe even find some less diabolically clever way of doing it ...

Thoughts?
Technical Details
Message-ID: <11d3o5d$3mitg$9@dont-email.me>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Lawrence D’Oliveiro <ldo@nz.invalid>
Newsgroups: comp.lang.c
Subject: Is This Sailing A Little Close To The Wind?
Date: Thu, 12 Nov 2026 06:59:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <11d3o5d$3mitg$9@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 12 Nov 2026 06:59:58 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3886000"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18VXvAlG7vA7ccDl+bIUCGd"; posting-host="33d00acd775bfe61d11222a1d44a73f8"
User-Agent: Pan/0.165 (Kostiantynivka)
Cancel-Lock: sha1:qGVeCF4LMNde7C70C8Yqxgu0UwU= sha256:1jjTu3FJa9ba+mfjwiLQyGOEfj7nzxWLS23+Kv3J9yE=
	sha1:xNhxtYxjccqiN8hynA1xZiczx/s= sha256:/yPZX0/8vrGHGAE4wIYr8wKdQJt0DvpnDTFvdn8kWQQ=