[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: "printf %d ''" should diagnose the empty string
From: |
Martin D Kealey |
Subject: |
Re: "printf %d ''" should diagnose the empty string |
Date: |
Thu, 21 Nov 2024 01:31:24 +1000 |
On Wed, 20 Nov 2024, 07:36 Paul Eggert, <eggert@cs.ucla.edu> wrote:
> However, I don't see why Bash should differ from POSIX behavior. Bash
> already diagnoses "printf %d x" and "printf %d ' '"; why should it be
> silent about "printf %d ''"?
>
>From a semantic perspective, because "" doesn't contain any non-digits.
>From an implementation perspective, the standard check for a valid number
is to call strtol() (or similar) and then see if there are any non-digits
remaining. It takes an extra check to see if it stopped without processing
any digits.
I'm in favour of treating the empty token (string) as being a valid way to
write zero, in the same way that 00 and 0000000 are also valid ways to
write zero. That makes it more consistent in ways that are useful.
I've heard appeals to "human" ways of writing numbers as a reason to forbid
treating an empty token as a valid way to write zero. I find such appeals
quite unconvincing, for the simple reason that human languages languages
have no rules at all for handling empty tokens (because they're
indistinguishable from no token at all).
-Martin
- "printf %d ''" should diagnose the empty string, Paul Eggert, 2024/11/19
- Re: "printf %d ''" should diagnose the empty string, #!microsuxx, 2024/11/19
- Re: "printf %d ''" should diagnose the empty string, #!microsuxx, 2024/11/19
- Re: "printf %d ''" should diagnose the empty string, Paul Eggert, 2024/11/19
- Re: "printf %d ''" should diagnose the empty string,
Martin D Kealey <=
- Re: "printf %d ''" should diagnose the empty string, Chet Ramey, 2024/11/20
- Re: "printf %d ''" should diagnose the empty string, Paul Eggert, 2024/11/20
- Re: "printf %d ''" should diagnose the empty string, Martin D Kealey, 2024/11/21
- Re: "printf %d ''" should diagnose the empty string, Paul Eggert, 2024/11/21
- Re: "printf %d ''" should diagnose the empty string, Martin D Kealey, 2024/11/22
- Re: "printf %d ''" should diagnose the empty string, Chet Ramey, 2024/11/22