Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <20240622145831.245@kylheku.com>
Deutsch   English   Français   Italiano  
<20240622145831.245@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: The difference between strtol() and strtoul() ?
Date: Sat, 22 Jun 2024 22:07:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 44
Message-ID: <20240622145831.245@kylheku.com>
References: <v51d1l$2fklr$1@news.xmission.com>
 <v540t9$2gsdu$1@news.xmission.com>
Injection-Date: Sun, 23 Jun 2024 00:07:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="84ae72b3df34410d1de3ee3e933d9441";
	logging-data="4155306"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+vJuywfuMyDY/jnNh2klbi3CzokGWWazw="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Zt+HRkPWP8cR0UCs3iUkuLWuC+M=
Bytes: 3065

On 2024-06-21, Kenny McCormack <gazelle@shell.xmission.com> wrote:
> In article <v51d1l$2fklr$1@news.xmission.com>,
> Kenny McCormack <gazelle@shell.xmission.com> wrote:
>>Interestingly, I note that strtoul() accepts strings that begin with a sign
>>(+ or -).  This is odd, since you'd (*) think that a sign (particularly, a
>>minus) would be a syntax error in parsing for an unsigned value.
>
> There have been some useful responses on this thread, which is Good.  Of
> course, there have also been the usual crappola-type responses, but one must
> learn to take the good with the bad.
>
> Anyway, I think the takeaway is that while it is what it is, an argument
> can certainly be made that it would have been better for the unsigned
> versions of these function to not accept signed input.  If I were designing
> it, I would have had strtoul("-1") be a syntax error (not a C language
> syntax error - but a meta-language syntax error) - or, if not that, then
> have it return 1, not 2**N-1.  But that's just me.

An alternative would be for the current minus handling behavior to apply
when the base is specified as zero, which is where the other hacks are
like leading 0 for octal and 0x  for hexadecimal (that one also
recognized in base 16).

> I appreciate the responses indicating that it was probably done the way it
> was for actually both of these reasons:
>     1) Because it makes it more useful for C compiler writers - who were
> 	seen as the primary audience.
>     2) Because it means that the two functions are literally the same code.
> 	Both calculate the same bit pattern - the difference is only in the
> 	caller's interpretation of the result.

3) The behavior is also useful for IT people who understand two's
complement computer arithmetic:

  voipserver --debug-mask=-1  # more convenient than --debug-mask=0xFFFFFFFF

It's why the 0x prefix is supported when base is 0, and also octal.

It supports not only compiler writing but system utilities.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca