Re: [PATCH v2 1/3] timespec.3type: tv_nsec is impl-def-type, glibc llong not a bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

On Sun, Jan 29, 2023 at 05:41:56PM +0100, Alejandro Colomar wrote:
> On 1/29/23 17:31, наб wrote:
> > +.PP
> > +.I tv_nsec
> > +is of an implementation-defined signed type capable of holding the specified range.
> Would you mind using interval here?
I don't think it makes sense here? Since (a) this is the standards
phrasing and (b) the /range/ of values is represented by an interval.

We could just as well say "all integers between 0 and 999`999`999",
or "integers at least 0 and smaller 1e9", which are both identical,
but aren't intervals per se. Or consider a similar case,
where the range would be "[0, 2^31-1] ∪ {EOF}" ‒
you wouldn't call that an interval, but it's a valid set expression;
timespec.3type is just a degenerate case.

In general, we're concerned with the logical object here
("the domain" or, well "range [of values]"),
not the implementation detail ("it's spelled with an interval").

Plus, I'd never search for "interval",
but most people would probably grep for "range",
because that's the sanest spelling.

> > -This is a long-standing and long-enshrined glibc bug
> > -.UR https://sourceware.org/bugzilla/show_bug.cgi?id=16437
> > -.I #16437
> > -.UE ,
> > -and an incompatible extension to the standards;
> > -however, as even a 32-bit
> > -.I long
> > -can hold the entire
> > -.I tv_nsec
> > -range,
> > -it's always safe to forcibly down-cast it to the standard type.
> If the C standards and POSIX don't want to add a type for it, let us
> disagree with their decission.
Let's not. This is valid /right now/ in no-flag (so "gnu18"?)
Clang trunk and bullseye GCC:
-- >8 --
$ cc -Wall -Wextra a.c
$ cat a.c
#include <time.h>

static void nsecify(typeof((struct timespec){}.tv_nsec) * n) {
        *n *= 2;
}

int main() {
        struct timespec q = {};
        __auto_type w = &q.tv_nsec;
        nsecify(w);
}
-- >8 --

And in C23 you'll be able to s/__auto_type/auto/.

> Let's add a bug:
> 
> There's no portable way to declare to pointer to tv_nsec, since you never
> know for sure if it will be long* or llong*.

Again, C23 has typeof() (kinda like decltype()), and on Clang trunk
  $ cc -Wall -Wextra a.c -std=c2x
already compiles cleanly;
the "portable way to declare a pointer to tv_nsec"
is to spell it exactly as "i want a pointer to timespec::tv_nsec",
which is even better than a single-use typedef.

Best,
наб

https://twitter.com/__phantomderp/status/1619027523257667584
(that's the C standard project editor shitposting; it's a glamorous age)

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3054.pdf
already has typeof and
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3079.htm
has the latest notes on auto, which n3091 marks as "Accepted with
comment: wording from N3079 with editorial corrections."

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux