Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

In theory, there is no difference between theory and practice. In practice, there is.


devel / comp.lang.c / Re: signed/unsigned - what will fail

SubjectAuthor
* signed/unsigned - what will failfir
`* Re: signed/unsigned - what will failfir
 +- Re: signed/unsigned - what will failfir
 `* Re: signed/unsigned - what will failÖö Tiib
  `* Re: signed/unsigned - what will failfir
   `* Re: signed/unsigned - what will failÖö Tiib
    `* Re: signed/unsigned - what will failDavid Brown
     +* Re: signed/unsigned - what will failMalcolm McLean
     |`* Re: signed/unsigned - what will failDavid Brown
     | `* Re: signed/unsigned - what will failBen Bacarisse
     |  `- Re: signed/unsigned - what will failTim Rentsch
     +* Re: signed/unsigned - what will failBart
     |+* Re: signed/unsigned - what will failDavid Brown
     ||+* Re: signed/unsigned - what will failScott Lurndal
     |||`* Re: signed/unsigned - what will failDavid Brown
     ||| `* Re: signed/unsigned - what will failScott Lurndal
     |||  `* Re: signed/unsigned - what will failDavid Brown
     |||   `* Re: signed/unsigned - what will failScott Lurndal
     |||    `- Re: signed/unsigned - what will failDavid Brown
     ||+* Re: signed/unsigned - what will failMalcolm McLean
     |||`* Re: signed/unsigned - what will failDavid Brown
     ||| +* Re: signed/unsigned - what will failfir
     ||| |+* Re: signed/unsigned - what will failfir
     ||| ||`* Re: signed/unsigned - what will failBen Bacarisse
     ||| || +* Re: signed/unsigned - what will failfir
     ||| || |`- Re: signed/unsigned - what will failfir
     ||| || `* Re: signed/unsigned - what will failfir
     ||| ||  `* Re: signed/unsigned - what will failBen Bacarisse
     ||| ||   `- Re: signed/unsigned - what will failfir
     ||| |`* Re: signed/unsigned - what will failfir
     ||| | `- Re: signed/unsigned - what will failfir
     ||| `- Re: signed/unsigned - what will failBen Bacarisse
     ||+* Re: signed/unsigned - what will failBart
     |||`- Re: signed/unsigned - what will failDavid Brown
     ||`* Re: signed/unsigned - what will failPhil Carmody
     || `* Re: signed/unsigned - what will failSpiros Bousbouras
     ||  `* Re: signed/unsigned - what will failSpiros Bousbouras
     ||   +- Re: signed/unsigned - what will failPhil Carmody
     ||   `- Re: signed/unsigned - what will failDavid Brown
     |`* Re: signed/unsigned - what will failKeith Thompson
     | `* Re: signed/unsigned - what will failBart
     |  `- Re: signed/unsigned - what will failKeith Thompson
     `* Re: signed/unsigned - what will failfir
      `* Re: signed/unsigned - what will failfir
       `- Re: signed/unsigned - what will failfir

Pages:12
Re: signed/unsigned - what will fail

<929255dd-9cf2-403d-af84-0b496d208215n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27800&group=comp.lang.c#27800

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1817:b0:40f:d6f0:7681 with SMTP id t23-20020a05622a181700b0040fd6f07681mr37654qtc.3.1692216784979;
Wed, 16 Aug 2023 13:13:04 -0700 (PDT)
X-Received: by 2002:a17:903:230e:b0:1bc:6799:3f69 with SMTP id
d14-20020a170903230e00b001bc67993f69mr1151384plh.12.1692216784398; Wed, 16
Aug 2023 13:13:04 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 16 Aug 2023 13:13:03 -0700 (PDT)
In-Reply-To: <5c329846-44fb-4875-8a0a-cbfe3b5c40bcn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.183; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.183
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me> <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
<5c329846-44fb-4875-8a0a-cbfe3b5c40bcn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <929255dd-9cf2-403d-af84-0b496d208215n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 20:13:04 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3882
 by: fir - Wed, 16 Aug 2023 20:13 UTC

środa, 16 sierpnia 2023 o 21:52:53 UTC+2 fir napisał(a):
> środa, 16 sierpnia 2023 o 19:30:28 UTC+2 fir napisał(a):
> > środa, 16 sierpnia 2023 o 19:21:28 UTC+2 David Brown napisał(a):
> > >
> > > if ((ch >= '0') && (ch <= '9)) {
> > > return ch - '0';
> > > }
> > there is a question if not write this
> >
> > if(ch>='0' & ch<='9') return ch - '0';
> >
> > i mean use & instead of &&, this && is kinda nonsense (skipping parenthesis i assume work coz im not sure, but better to assume and debug imo)
> i checked if this work and seem to be ok
>
> char c ='3'; if(c>='0'&c<='9') printf("%d",c-'0');
>
> btw the more long i c then i tend to write with syntax that can
> be considered tricks (like long vertical lines, short syntax..but imo its right
> way becouse what may be considered little trouble for nob it is none
> if youre just familiar
>
> painfull are though the c flops not alowing use some shortcuts where there is
> nothing thatdisallows them on semantic level (mainly like instantiating
> variables inside some contructs etc)
>
> conclusions
>
> THOSE WHO MANAGE EXTENSIONS TO C SHOULD ALLOW THAT,
> I MEAN ALLOW THAT SYNTAX EXTENSIONS
>
> really, it would not break c and would be much pleasant

btw speaking of ifs some observation on switch case unconsequence
(ratcher unpleasant)

case resembles if except you write case(2) instead of if(c==2),
i mean switch(c) case(1) case(2) default; is proper syntax for it
yhis what is right now is bad

ommiting those parenthesis is bad also no need to enclosing {}
on all construct

switch(p)
case(1) a(); case(2) b();
just like if, the additional statemnts

case(1) a(); c(); case(2) b();
like c(); here should be either just executed as free (not part of case(1)
or disallowed

in the way it is roght now its syntax incoherence imo (as case is close to of and no need to break this syntax imo)

btw the holes in if-else also should be either executed or disallowed

if(a==2) foo(); bar(); else zoo();

Re: signed/unsigned - what will fail

<87bkf6loo7.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27801&group=comp.lang.c#27801

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Wed, 16 Aug 2023 13:26:00 -0700
Organization: None to speak of
Lines: 13
Message-ID: <87bkf6loo7.fsf@nosuchdomain.example.com>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="15135efa85b793336b66170ecb85b528";
logging-data="3599848"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iGUKEGqIBW1LyZBRoIvkY"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:QHS8M0cxQUBxF3ZILrdpO4kzdJw=
sha1:8WxZ0XdiGJvmvxiSOc7shgDpCdk=
 by: Keith Thompson - Wed, 16 Aug 2023 20:26 UTC

Bart <bc@freeuk.com> writes:
[...]
> Unfortunately, in C, string literals have type char*, and char*
> strings are encountered everywhere, where they can store ASCII,
> extended ASCII of various kinds, or UTF8.

No, string literals are of type char[N], where N is the length of the
literal plus 1.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: signed/unsigned - what will fail

<ubjcsv$3efav$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27804&group=comp.lang.c#27804

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Wed, 16 Aug 2023 21:51:44 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ubjcsv$3efav$1@dont-email.me>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<87bkf6loo7.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 16 Aug 2023 20:51:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="17f8aedb09110eed4ec1c7adfd187d70";
logging-data="3620191"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198niXupd+xbrQdhKFpln3EzKpu07FEsFc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:1d9cTsIAxrq24lL3vAoA8QbCOM8=
In-Reply-To: <87bkf6loo7.fsf@nosuchdomain.example.com>
 by: Bart - Wed, 16 Aug 2023 20:51 UTC

On 16/08/2023 21:26, Keith Thompson wrote:
> Bart <bc@freeuk.com> writes:
> [...]
>> Unfortunately, in C, string literals have type char*, and char*
>> strings are encountered everywhere, where they can store ASCII,
>> extended ASCII of various kinds, or UTF8.
>
> No, string literals are of type char[N], where N is the length of the
> literal plus 1.
>

Which is usually converted to type char*?

But this makes little difference to my point: you can't really get away
from C's plain 'char' type if dealing with text and strings.

Re: signed/unsigned - what will fail

<87bkf6hfr5.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27805&group=comp.lang.c#27805

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Wed, 16 Aug 2023 21:52:14 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <87bkf6hfr5.fsf@bsb.me.uk>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me>
<9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="f23095e1eb81acb3fb188baae9243a4f";
logging-data="3621131"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BOWBpoCS04O7D0iCSKXI417wTvw9a9q4="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:iusA/CW2aiqQGOKX1kfymll9zrM=
sha1:MsXBubZBYHwBZMel3DUu3uAP9NA=
X-BSB-Auth: 1.8ebbe87d7201d1b1f4ba.20230816215214BST.87bkf6hfr5.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 16 Aug 2023 20:52 UTC

David Brown <david.brown@hesbynett.no> writes:

> On 16/08/2023 16:35, Malcolm McLean wrote:
>> On Wednesday, 16 August 2023 at 14:31:51 UTC+1, David Brown wrote:

>>> I think it is entirely appropriate to use "char" for characters (and
>>> const char* for immutable strings). But I don't think it is appropriate
>>> for any kind of arithmetic.
>>>
>> Theoretically an atoi() should be implemeted with
>
> I'm not sure "should be" is the phrase you are looking for here!
>
>> strchr("0123456789", ch);

That's a rather oblique hint. You can't use strchr unless you record
the pointer to the digit string:

const char *digits = "0123456789";

now, when ch is a digit, strchr(digits, ch) - digits gives ch's value as
a digit. But since this only works for valid digits, we probably want
something more like

const char *digits = "0123456789", *found = strchr(digits, ch);
return found ? found - digits : -1;

>> to convert from character to digit. But people like efficiency.
>
> It would still not be arithmetic on chars.

That's Malcolm's point. He's countering your "no arithmetic on chars"
by saying we'd be forced to use something like a search and people like
efficiency.

But then atoi is a library function and I am sure you did not intend you
prohibition to extend to the internals of an implementation.

Anyway, as you go on to say...

> But you /could/ have code such as :
>
> if ((ch >= '0') && (ch <= '9)) {
> return ch - '0';
> }
>
> That would be arithmetic on chars. Well, obviously the actual arithmetic
> is on chars promoted to int (or unsigned int, if plain char is unsigned at
> the same size as int) - but you know what I mean.
>
> The C standard requires a character set in which '0' to '9' are
> consecutive, so that kind of code will be fully defined.

.... this one is fine. In fact, I would not go so far as to say "on
arithmetic on chars" because of thins like this.

--
Ben.

Re: signed/unsigned - what will fail

<875y5ehfc2.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27806&group=comp.lang.c#27806

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Wed, 16 Aug 2023 22:01:17 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <875y5ehfc2.fsf@bsb.me.uk>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me>
<9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me>
<a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
<fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="f23095e1eb81acb3fb188baae9243a4f";
logging-data="3621131"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eLoFXXIRCSA381SPg0FDrOlIGSMpB/oI="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:QvZ+BLOzf72ve+0rDLmOUHKl7JE=
sha1:b6hcukVdS8Dkco66GICTS29+C2g=
X-BSB-Auth: 1.6f84a0f296542ec6bd61.20230816220117BST.875y5ehfc2.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 16 Aug 2023 21:01 UTC

fir <profesor.fir@gmail.com> writes:

> środa, 16 sierpnia 2023 o 19:30:28 UTC+2 fir napisał(a):
>> środa, 16 sierpnia 2023 o 19:21:28 UTC+2 David Brown napisał(a):
>> >
>> > if ((ch >= '0') && (ch <= '9)) {
>> > return ch - '0';
>> > }
>> there is a question if not write this
>>
>> if(ch>='0' & ch<='9') return ch - '0';
>>
>> i mean use & instead of &&, this && is kinda nonsense (skipping
>> parenthesis i assume work coz im not sure, but better to assume and
>> debug imo)
>
> the decision not to use && for bitwiseand and || for bitwise was
> clearly idiotic and the question is who did it? ...normal and as & and
> normal or as | is quite standable

Clearly you don't know why this decision was made, yet you are sure it
was idiotic! That's not a good look.

You can find out the whole story with a bit of searching on the web
(keywords: Dennis Ritchie C history Bell Labs).

--
Ben.

Re: signed/unsigned - what will fail

<61ecde09-20bf-40e8-a3b6-aefa168f35a5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27807&group=comp.lang.c#27807

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1a28:b0:403:edaf:5952 with SMTP id f40-20020a05622a1a2800b00403edaf5952mr36730qtb.1.1692220167059;
Wed, 16 Aug 2023 14:09:27 -0700 (PDT)
X-Received: by 2002:a17:90a:fe86:b0:268:3469:d86e with SMTP id
co6-20020a17090afe8600b002683469d86emr631553pjb.1.1692220166142; Wed, 16 Aug
2023 14:09:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 16 Aug 2023 14:09:25 -0700 (PDT)
In-Reply-To: <875y5ehfc2.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.61; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.61
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me> <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
<fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com> <875y5ehfc2.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <61ecde09-20bf-40e8-a3b6-aefa168f35a5n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 21:09:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2953
 by: fir - Wed, 16 Aug 2023 21:09 UTC

środa, 16 sierpnia 2023 o 23:01:32 UTC+2 Ben Bacarisse napisał(a):
> fir <profes...@gmail.com> writes:
>
> > środa, 16 sierpnia 2023 o 19:30:28 UTC+2 fir napisał(a):
> >> środa, 16 sierpnia 2023 o 19:21:28 UTC+2 David Brown napisał(a):
> >> >
> >> > if ((ch >= '0') && (ch <= '9)) {
> >> > return ch - '0';
> >> > }
> >> there is a question if not write this
> >>
> >> if(ch>='0' & ch<='9') return ch - '0';
> >>
> >> i mean use & instead of &&, this && is kinda nonsense (skipping
> >> parenthesis i assume work coz im not sure, but better to assume and
> >> debug imo)
> >
> > the decision not to use && for bitwiseand and || for bitwise was
> > clearly idiotic and the question is who did it? ...normal and as & and
> > normal or as | is quite standable
> Clearly you don't know why this decision was made, yet you are sure it
> was idiotic! That's not a good look.
>

i see the bad (idiotic) results - so the decisions leading to them are idiotoc..
im not so bad in logic here

> You can find out the whole story with a bit of searching on the web
> (keywords: Dennis Ritchie C history Bell Labs).
>

Re: signed/unsigned - what will fail

<b9415e0d-c3f3-47aa-b3a6-d298cdf4fc60n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27808&group=comp.lang.c#27808

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:4f:b0:40c:84bb:1b09 with SMTP id y15-20020a05622a004f00b0040c84bb1b09mr11772qtw.0.1692220466618;
Wed, 16 Aug 2023 14:14:26 -0700 (PDT)
X-Received: by 2002:a05:6a00:18a4:b0:686:7119:2a4d with SMTP id
x36-20020a056a0018a400b0068671192a4dmr1471901pfh.2.1692220466395; Wed, 16 Aug
2023 14:14:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 16 Aug 2023 14:14:25 -0700 (PDT)
In-Reply-To: <875y5ehfc2.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.61; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.61
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me> <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
<fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com> <875y5ehfc2.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b9415e0d-c3f3-47aa-b3a6-d298cdf4fc60n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 21:14:26 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3118
 by: fir - Wed, 16 Aug 2023 21:14 UTC

środa, 16 sierpnia 2023 o 23:01:32 UTC+2 Ben Bacarisse napisał(a):
> fir <profes...@gmail.com> writes:
>
> > środa, 16 sierpnia 2023 o 19:30:28 UTC+2 fir napisał(a):
> >> środa, 16 sierpnia 2023 o 19:21:28 UTC+2 David Brown napisał(a):
> >> >
> >> > if ((ch >= '0') && (ch <= '9)) {
> >> > return ch - '0';
> >> > }
> >> there is a question if not write this
> >>
> >> if(ch>='0' & ch<='9') return ch - '0';
> >>
> >> i mean use & instead of &&, this && is kinda nonsense (skipping
> >> parenthesis i assume work coz im not sure, but better to assume and
> >> debug imo)
> >
> > the decision not to use && for bitwiseand and || for bitwise was
> > clearly idiotic and the question is who did it? ...normal and as & and
> > normal or as | is quite standable
> Clearly you don't know why this decision was made, yet you are sure it
> was idiotic! That's not a good look.
>
> You can find out the whole story with a bit of searching on the web
> (keywords: Dennis Ritchie C history Bell Labs).
>
yyou may quote what was that as im not in mood to search long text ..overally people posting reference to long text assuming somebody has so much time to search this behave not much wise imo

Re: signed/unsigned - what will fail

<30a82e99-378c-4f8d-a019-35372b012898n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27810&group=comp.lang.c#27810

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5907:0:b0:403:b221:e4b4 with SMTP id 7-20020ac85907000000b00403b221e4b4mr38621qty.1.1692221347378;
Wed, 16 Aug 2023 14:29:07 -0700 (PDT)
X-Received: by 2002:a05:6a00:992:b0:67d:41a8:3e19 with SMTP id
u18-20020a056a00099200b0067d41a83e19mr1601424pfg.3.1692221346432; Wed, 16 Aug
2023 14:29:06 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 16 Aug 2023 14:29:05 -0700 (PDT)
In-Reply-To: <61ecde09-20bf-40e8-a3b6-aefa168f35a5n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.50; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.50
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me> <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
<fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com> <875y5ehfc2.fsf@bsb.me.uk>
<61ecde09-20bf-40e8-a3b6-aefa168f35a5n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <30a82e99-378c-4f8d-a019-35372b012898n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 21:29:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3603
 by: fir - Wed, 16 Aug 2023 21:29 UTC

środa, 16 sierpnia 2023 o 23:09:34 UTC+2 fir napisał(a):
> środa, 16 sierpnia 2023 o 23:01:32 UTC+2 Ben Bacarisse napisał(a):
> > fir <profes...@gmail.com> writes:
> >
> > > środa, 16 sierpnia 2023 o 19:30:28 UTC+2 fir napisał(a):
> > >> środa, 16 sierpnia 2023 o 19:21:28 UTC+2 David Brown napisał(a):
> > >> >
> > >> > if ((ch >= '0') && (ch <= '9)) {
> > >> > return ch - '0';
> > >> > }
> > >> there is a question if not write this
> > >>
> > >> if(ch>='0' & ch<='9') return ch - '0';
> > >>
> > >> i mean use & instead of &&, this && is kinda nonsense (skipping
> > >> parenthesis i assume work coz im not sure, but better to assume and
> > >> debug imo)
> > >
> > > the decision not to use && for bitwiseand and || for bitwise was
> > > clearly idiotic and the question is who did it? ...normal and as & and
> > > normal or as | is quite standable
> > Clearly you don't know why this decision was made, yet you are sure it
> > was idiotic! That's not a good look.
> >
> i see the bad (idiotic) results - so the decisions leading to them are idiotoc..
> im not so bad in logic here
> > You can find out the whole story with a bit of searching on the web
> > (keywords: Dennis Ritchie C history Bell Labs).
> >

c has some idiotic decisions, but noticing which one are idiotic is not so easy

idiotic is for example decision that local variables in if block or for block are
local to that block, its verry annoying and thsi is idiotic... those blocks in
many cases are not separate blocks when you need to destroy variables but just logical branches .. and the need to declare variables before that vlock is opposite to sugar

Re: signed/unsigned - what will fail

<87zg2qfyy8.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27811&group=comp.lang.c#27811

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Wed, 16 Aug 2023 22:40:31 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <87zg2qfyy8.fsf@bsb.me.uk>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me>
<aedc8f63-5638-4d24-a116-594dc63c8fa4n@googlegroups.com>
<ubiahg$394g8$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="f23095e1eb81acb3fb188baae9243a4f";
logging-data="3633304"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NPSqS8BGA4s8EcdaGGoPj0vOWl5QzRRg="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:n7KPZOvPEeJ2qpH4c1SwJIjvVpA=
sha1:KtSra+vihSeVcik+EBTZWRoV2Jo=
X-BSB-Auth: 1.09e2e6052d591df51c06.20230816224031BST.87zg2qfyy8.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 16 Aug 2023 21:40 UTC

David Brown <david.brown@hesbynett.no> writes:

> On 16/08/2023 09:02, Malcolm McLean wrote:
>> On Wednesday, 16 August 2023 at 07:53:32 UTC+1, David Brown wrote:

>>> It is, of course, a terrible idea to do any kind of arithmetic or hold
>>> numbers in plain char - use them for 7-bit ASCII characters only.
>>>
>> I pass about UTF-8 as char *s in Baby X. But of course it is
>> converted to unsigned char for the actual UTF-8 manipulations.

I think too much is often made of this. What is it that you are worried
about? A lot of UTF-8 fiddling is masking values that will have been
promoted to int. The masking can be more portable than the conversion.

> Conversion from plain char to unsigned char will always be safe and
> well-defined, regardless of the signedness of plain char.

It's not UB in the dreaded C sense, but it's not defined in a way that
will help you for UTF-8. Let's say you want to see if *cp (a plain
pointer to signed char) points to a UTF-8 continuation character. I'd
write

(*cp & 0xC0) == 0x80

and the value of six bits represented is *cp & 0x3F, i.e. 2.

Will this fail because char is signed? No. Will it fail if char is
signed and the implementation uses sign-and-magnitude? I don't think so
because UTF-8 mandates the bit pattern not the value. (If anyone has
ever seen UTF-8 on a non-two's complement machine with signed char, do
let me know!)

> And it is always
> safe to access plain char data through an unsigned char pointer.

But what happens if I convert to unsigned char:

const unsigned char *ucp = cp;

Now what is *cp & 0x3F on a sign-and-magnitude machine? It's 62 not 2.

Admittedly, anything but two's complement is now relegated to C's
history even if the machines still exist, so may we should not care
anymore.

--
Ben.

Re: signed/unsigned - what will fail

<87y1iak44d.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27814&group=comp.lang.c#27814

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Wed, 16 Aug 2023 15:35:14 -0700
Organization: None to speak of
Lines: 23
Message-ID: <87y1iak44d.fsf@nosuchdomain.example.com>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<87bkf6loo7.fsf@nosuchdomain.example.com>
<ubjcsv$3efav$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="b05999d425cd7ec276267a84f508b846";
logging-data="3646224"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19jh6JeXhmjdKTPtGiNPcBp"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:Fq8DKPqdfui/iO/287Rzv4nddP8=
sha1:QqfRQhCRfyHbj/OwBvM+S/j93mU=
 by: Keith Thompson - Wed, 16 Aug 2023 22:35 UTC

Bart <bc@freeuk.com> writes:
> On 16/08/2023 21:26, Keith Thompson wrote:
>> Bart <bc@freeuk.com> writes:
>> [...]
>>> Unfortunately, in C, string literals have type char*, and char*
>>> strings are encountered everywhere, where they can store ASCII,
>>> extended ASCII of various kinds, or UTF8.
>> No, string literals are of type char[N], where N is the length of the
>> literal plus 1.
>
> Which is usually converted to type char*?

Yes, usually, but by no means always.

> But this makes little difference to my point: you can't really get
> away from C's plain 'char' type if dealing with text and strings.

Agreed.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Re: signed/unsigned - what will fail

<87il9efsv2.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27818&group=comp.lang.c#27818

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 00:52:01 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <87il9efsv2.fsf@bsb.me.uk>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me>
<9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me>
<a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
<fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com>
<875y5ehfc2.fsf@bsb.me.uk>
<b9415e0d-c3f3-47aa-b3a6-d298cdf4fc60n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="c666b555a840b444cd6c032219f8b5e7";
logging-data="3657358"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192yLeJWMGBCZX0iqdNYXSWUcJGorefDbE="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux)
Cancel-Lock: sha1:8O3C4Za2rcahWtVHtK2vxEtEkLQ=
sha1:utcJd7x0k4cHt+HhTa43rax8TvA=
X-BSB-Auth: 1.97d6ec8c67fea7c3f4ae.20230817005201BST.87il9efsv2.fsf@bsb.me.uk
 by: Ben Bacarisse - Wed, 16 Aug 2023 23:52 UTC

fir <profesor.fir@gmail.com> writes:

> środa, 16 sierpnia 2023 o 23:01:32 UTC+2 Ben Bacarisse napisał(a):
>> fir <profes...@gmail.com> writes:
>>
>> > środa, 16 sierpnia 2023 o 19:30:28 UTC+2 fir napisał(a):
>> >> środa, 16 sierpnia 2023 o 19:21:28 UTC+2 David Brown napisał(a):
>> >> >
>> >> > if ((ch >= '0') && (ch <= '9)) {
>> >> > return ch - '0';
>> >> > }
>> >> there is a question if not write this
>> >>
>> >> if(ch>='0' & ch<='9') return ch - '0';
>> >>
>> >> i mean use & instead of &&, this && is kinda nonsense (skipping
>> >> parenthesis i assume work coz im not sure, but better to assume and
>> >> debug imo)
>> >
>> > the decision not to use && for bitwiseand and || for bitwise was
>> > clearly idiotic and the question is who did it? ...normal and as & and
>> > normal or as | is quite standable
>> Clearly you don't know why this decision was made, yet you are sure it
>> was idiotic! That's not a good look.
>>
>> You can find out the whole story with a bit of searching on the web
>> (keywords: Dennis Ritchie C history Bell Labs).
>>
> yyou may quote what was that as im not in mood to search long text
> ..overally people posting reference to long text assuming somebody has
> so much time to search this behave not much wise imo

But I should take the time to explain the reasons to you? You don't
want to read up on why C's design is not "idiotic", and I don't want to
try to explain it to you.

--
Ben.

Re: signed/unsigned - what will fail

<d41127ee-c0fe-4f80-928e-7871b9044b16n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27820&group=comp.lang.c#27820

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:48:b0:403:b888:fa29 with SMTP id y8-20020a05622a004800b00403b888fa29mr35925qtw.0.1692230866751;
Wed, 16 Aug 2023 17:07:46 -0700 (PDT)
X-Received: by 2002:a63:3d45:0:b0:569:1460:bbf1 with SMTP id
k66-20020a633d45000000b005691460bbf1mr112511pga.11.1692230865812; Wed, 16 Aug
2023 17:07:45 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Wed, 16 Aug 2023 17:07:45 -0700 (PDT)
In-Reply-To: <87il9efsv2.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.214; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.214
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
<ubj0i9$3ckl4$2@dont-email.me> <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
<fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com> <875y5ehfc2.fsf@bsb.me.uk>
<b9415e0d-c3f3-47aa-b3a6-d298cdf4fc60n@googlegroups.com> <87il9efsv2.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d41127ee-c0fe-4f80-928e-7871b9044b16n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Thu, 17 Aug 2023 00:07:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3585
 by: fir - Thu, 17 Aug 2023 00:07 UTC

czwartek, 17 sierpnia 2023 o 01:52:15 UTC+2 Ben Bacarisse napisał(a):
> fir <profes...@gmail.com> writes:
>
> > środa, 16 sierpnia 2023 o 23:01:32 UTC+2 Ben Bacarisse napisał(a):
> >> fir <profes...@gmail.com> writes:
> >>
> >> > środa, 16 sierpnia 2023 o 19:30:28 UTC+2 fir napisał(a):
> >> >> środa, 16 sierpnia 2023 o 19:21:28 UTC+2 David Brown napisał(a):
> >> >> >
> >> >> > if ((ch >= '0') && (ch <= '9)) {
> >> >> > return ch - '0';
> >> >> > }
> >> >> there is a question if not write this
> >> >>
> >> >> if(ch>='0' & ch<='9') return ch - '0';
> >> >>
> >> >> i mean use & instead of &&, this && is kinda nonsense (skipping
> >> >> parenthesis i assume work coz im not sure, but better to assume and
> >> >> debug imo)
> >> >
> >> > the decision not to use && for bitwiseand and || for bitwise was
> >> > clearly idiotic and the question is who did it? ...normal and as & and
> >> > normal or as | is quite standable
> >> Clearly you don't know why this decision was made, yet you are sure it
> >> was idiotic! That's not a good look.
> >>
> >> You can find out the whole story with a bit of searching on the web
> >> (keywords: Dennis Ritchie C history Bell Labs).
> >>
> > yyou may quote what was that as im not in mood to search long text
> > ..overally people posting reference to long text assuming somebody has
> > so much time to search this behave not much wise imo
> But I should take the time to explain the reasons to you? You don't
> want to read up on why C's design is not "idiotic", and I don't want to
> try to explain it to you.
>
so why you talk on it? are you an idiot?

Re: signed/unsigned - what will fail

<86bkf65pm4.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27827&group=comp.lang.c#27827

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Wed, 16 Aug 2023 20:12:19 -0700
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <86bkf65pm4.fsf@linuxsc.com>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com> <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com> <6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com> <ubhrot$37a4c$1@dont-email.me> <aedc8f63-5638-4d24-a116-594dc63c8fa4n@googlegroups.com> <ubiahg$394g8$4@dont-email.me> <87zg2qfyy8.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="a8782d2d7d1c356e90db8dd7e2df2f84";
logging-data="3831301"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iBEEH1wWTlNAYFrPN25MzjtAOoioCflY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:3bryD5Hw9ci+yE1M2+lUd9NGB6E=
sha1:3nrrtqoBZ6ANpTTjTe/uXMC4yjs=
 by: Tim Rentsch - Thu, 17 Aug 2023 03:12 UTC

Ben Bacarisse <ben.usenet@bsb.me.uk> writes:

> David Brown <david.brown@hesbynett.no> writes:
>
>> On 16/08/2023 09:02, Malcolm McLean wrote:
>>
>>> On Wednesday, 16 August 2023 at 07:53:32 UTC+1, David Brown wrote:
>>>
>>>> It is, of course, a terrible idea to do any kind of arithmetic or
>>>> hold numbers in plain char - use them for 7-bit ASCII characters
>>>> only.
>>>
>>> I pass about UTF-8 as char *s in Baby X. But of course it is
>>> converted to unsigned char for the actual UTF-8 manipulations.
>
> I think too much is often made of this. What is it that you are
> worried about? A lot of UTF-8 fiddling is masking values that will
> have been promoted to int. The masking can be more portable than
> the conversion.

I'm not sure the question is so clear cut. First the pointer
conversion (from char * to unsigned char *) is absolutely
guaranteed to work, and accesses through the unsigned char * are
guaranteed to work. The only question is what bits do you get.
Of course if the implementation is two's complement then it
doesn't matter. But if it isn't, where did the bits come from?
That matters because values that go through <stdio.h> functions
may have been converted to -- or re-interpreted as, it isn't
clear which -- unsigned char. If a file is being read that was
produced under a different implementation, reading the bytes as
char's rather than unsigned char's could result in incorrect
values. Or, unfortunately, vice versa.

Speaking for myself normally I would prefer to do UTF8-style
processing through unsigned char pointers. My reasoning is it's
easier to think about and (probably) more likely to work in the
unusual cases. Also, now that I think of it, safer, because
unsigned char cannot have trap representations. Also if there is
some sort of encoding problem I have more confidence in solving
the problem working directly on unsigned char values than in
reasoning through what will happen when working with the signed
values. Conversely if I were reading code that was doing UTF8
processing and using plain char, I think I would need to work
harder to understand how it works. So FWIW there is a personal
view.

Re: signed/unsigned - what will fail

<874jky2jvm.fsf@fatphil.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27829&group=comp.lang.c#27829

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pc+use...@asdf.org (Phil Carmody)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 10:44:29 +0300
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <874jky2jvm.fsf@fatphil.org>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: dont-email.me; posting-host="c5ae6d758bdcdf7c941356aad3a595c3";
logging-data="3895206"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HIDt7WQt3Trnt7/FGvWsQ"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Cancel-Lock: sha1:CMSmy/0CLR0RBW8MBuPgA6FvNRA=
sha1:w+1zrryGkplT5js0yVYupqIbEEg=
 by: Phil Carmody - Thu, 17 Aug 2023 07:44 UTC

David Brown <david.brown@hesbynett.no> writes:
> On 16/08/2023 14:31, Bart wrote:
>> On 16/08/2023 07:53, David Brown wrote:
>>> Just to be clear about this in case anyone wonders why you wrote
>>> that - plain "char" can be signed or unsigned, depending on the
>>> platform. Older platforms (including x86) tend to have plain char
>>> as signed, while more modern ABIs are usually unsigned.
>>>
>>> It is, of course, a terrible idea to do any kind of arithmetic or
>>> hold numbers in plain char - use them for 7-bit ASCII characters
>>> only.  For anything with numbers, use "signed char", "unsigned
>>> char", or (better, IMHO) appropriate <stdint.h> types when you need
>>> a small integer type.
>>
>> Unfortunately, in C, string literals have type char*, and char*
>> strings are encountered everywhere, where they can store ASCII,
>> extended ASCII of various kinds, or UTF8.
>>
>> But you frequently need to manipulate individual character codes.
>
> It's quite rare to have to manipulate characters individually, other
> than perhaps comparing them to character constants. Certainly general
> arithmetic is very rare on characters, with the exception of something
> like UTF8 code point extraction. Do you have examples where people
> might reasonably want to perform arithmetic on plain char, that you
> think occur frequently?
>
> I think it is entirely appropriate to use "char" for characters (and
> const char* for immutable strings). But I don't think it is
> appropriate for any kind of arithmetic.

How would you hash a string (for example for insertion in a hash table)
without arithmetic?

Phil
--
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/

Re: signed/unsigned - what will fail

<V6176aqfRxbq1pWTx@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27830&group=comp.lang.c#27830

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 08:17:52 -0000 (UTC)
Organization: To protect and to server
Message-ID: <V6176aqfRxbq1pWTx@bongo-ra.co>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com> <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com> <ubhrot$37a4c$1@dont-email.me>
<ubifj9$39v7p$1@dont-email.me> <ubij3o$3afvd$1@dont-email.me> <874jky2jvm.fsf@fatphil.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 17 Aug 2023 08:17:52 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="3310564"; posting-host="9H7U5kayiTdk7VIdYU44Rw.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
Cancel-Lock: sha256:1Y0CZQsD44vPSQHxR2AjTBdVo40QNJNhtF9w0xDVV1U=
X-Organisation: Weyland-Yutani
X-Server-Commands: nowebcancel
X-Notice: Filtered by postfilter v. 0.9.3
 by: Spiros Bousbouras - Thu, 17 Aug 2023 08:17 UTC

On Thu, 17 Aug 2023 10:44:29 +0300
Phil Carmody <pc+usenet@asdf.org> wrote:
> David Brown <david.brown@hesbynett.no> writes:
> > It's quite rare to have to manipulate characters individually, other
> > than perhaps comparing them to character constants. Certainly general
> > arithmetic is very rare on characters, with the exception of something
> > like UTF8 code point extraction. Do you have examples where people
> > might reasonably want to perform arithmetic on plain char, that you
> > think occur frequently?
> >
> > I think it is entirely appropriate to use "char" for characters (and
> > const char* for immutable strings). But I don't think it is
> > appropriate for any kind of arithmetic.
>
> How would you hash a string (for example for insertion in a hash table)
> without arithmetic?

You would cast each element of the string to an unsigned integer type
which won't get promoted to a signed type ; so unsigned int at least.
And then you would feed your hash function the unsigned integers. How
wide these would need to be depends on how many bits the hash values
are supposed to have.

Re: signed/unsigned - what will fail

<Q3ZGZO0rTkDNfg8TU@bongo-ra.co>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27831&group=comp.lang.c#27831

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!not-for-mail
From: spi...@gmail.com (Spiros Bousbouras)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 08:51:33 -0000 (UTC)
Organization: To protect and to server
Message-ID: <Q3ZGZO0rTkDNfg8TU@bongo-ra.co>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com> <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com> <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com> <ubhrot$37a4c$1@dont-email.me>
<ubifj9$39v7p$1@dont-email.me> <ubij3o$3afvd$1@dont-email.me> <874jky2jvm.fsf@fatphil.org>
<V6176aqfRxbq1pWTx@bongo-ra.co>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 17 Aug 2023 08:51:33 -0000 (UTC)
Injection-Info: paganini.bofh.team; logging-data="3316536"; posting-host="9H7U5kayiTdk7VIdYU44Rw.user.paganini.bofh.team"; mail-complaints-to="usenet@bofh.team"; posting-account="9dIQLXBM7WM9KzA+yjdR4A";
Cancel-Lock: sha256:IVgt1EDmDz7zYAWwDCg2v1L6ttby6uP9I0mEfTjCfls=
X-Server-Commands: nowebcancel
X-Notice: Filtered by postfilter v. 0.9.3
X-Organisation: Weyland-Yutani
 by: Spiros Bousbouras - Thu, 17 Aug 2023 08:51 UTC

On Thu, 17 Aug 2023 08:17:52 -0000 (UTC)
Spiros Bousbouras <spibou@gmail.com> wrote:
> On Thu, 17 Aug 2023 10:44:29 +0300
> Phil Carmody <pc+usenet@asdf.org> wrote:
> > David Brown <david.brown@hesbynett.no> writes:
> > > It's quite rare to have to manipulate characters individually, other
> > > than perhaps comparing them to character constants. Certainly general
> > > arithmetic is very rare on characters, with the exception of something
> > > like UTF8 code point extraction. Do you have examples where people
> > > might reasonably want to perform arithmetic on plain char, that you
> > > think occur frequently?
> > >
> > > I think it is entirely appropriate to use "char" for characters (and
> > > const char* for immutable strings). But I don't think it is
> > > appropriate for any kind of arithmetic.
> >
> > How would you hash a string (for example for insertion in a hash table)
> > without arithmetic?
>
> You would cast each element of the string to an unsigned integer type
> which won't get promoted to a signed type ; so unsigned int at least.
> And then you would feed your hash function the unsigned integers. How
> wide these would need to be depends on how many bits the hash values
> are supposed to have.

Come to think of it , it has been discussed several times on this group
whether wraparound arithmetic is ever useful. It is useful for hashing and
also for pseudorandom number generators. But for such applications , using
non negative integers is probably preferable.

--
vlaho.ninja/prog

Re: signed/unsigned - what will fail

<87pm3lzx4y.fsf@fatphil.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27844&group=comp.lang.c#27844

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: pc+use...@asdf.org (Phil Carmody)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 15:11:41 +0300
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <87pm3lzx4y.fsf@fatphil.org>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <874jky2jvm.fsf@fatphil.org>
<V6176aqfRxbq1pWTx@bongo-ra.co> <Q3ZGZO0rTkDNfg8TU@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="c5ae6d758bdcdf7c941356aad3a595c3";
logging-data="3972763"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AU+V4nb9W+oFDvf+OExUG"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)
Cancel-Lock: sha1:eiQhJQ1xZ90cZ0535SVR+US2evQ=
sha1:7YWSy+de/26+MKwKBRbcSv9bba0=
 by: Phil Carmody - Thu, 17 Aug 2023 12:11 UTC

Spiros Bousbouras <spibou@gmail.com> writes:
> On Thu, 17 Aug 2023 08:17:52 -0000 (UTC)
> Spiros Bousbouras <spibou@gmail.com> wrote:
>> On Thu, 17 Aug 2023 10:44:29 +0300
>> Phil Carmody <pc+usenet@asdf.org> wrote:
>> > David Brown <david.brown@hesbynett.no> writes:
>> > > It's quite rare to have to manipulate characters individually, other
>> > > than perhaps comparing them to character constants. Certainly general
>> > > arithmetic is very rare on characters, with the exception of something
>> > > like UTF8 code point extraction. Do you have examples where people
>> > > might reasonably want to perform arithmetic on plain char, that you
>> > > think occur frequently?
>> > >
>> > > I think it is entirely appropriate to use "char" for characters (and
>> > > const char* for immutable strings). But I don't think it is
>> > > appropriate for any kind of arithmetic.
>> >
>> > How would you hash a string (for example for insertion in a hash table)
>> > without arithmetic?
>>
>> You would cast each element of the string to an unsigned integer type
>> which won't get promoted to a signed type ; so unsigned int at least.
>> And then you would feed your hash function the unsigned integers. How
>> wide these would need to be depends on how many bits the hash values
>> are supposed to have.
>
> Come to think of it , it has been discussed several times on this group
> whether wraparound arithmetic is ever useful. It is useful for hashing and
> also for pseudorandom number generators. But for such applications , using
> non negative integers is probably preferable.

Yup, I agree. My example was not a particularly good one at all. Alas,
I think that the pedantic nature of there being up-conversions to int
before the operations are performed, even if the result desired is
another char is confusing matters. I'd say that there are two entirely
supportable answers to the question "is this arithmetic on chars?":
char a=get_a(), b=get_b();
char c=a+b;
For the initial question to even make sense, you need to be prepared to
ignore the pedantic definition of the operation - as it demands that the
answer is "yes".

Phil
--
We are no longer hunters and nomads. No longer awed and frightened, as we have
gained some understanding of the world in which we live. As such, we can cast
aside childish remnants from the dawn of our civilization.
-- NotSanguine on SoylentNews, after Eugen Weber in /The Western Tradition/

Re: signed/unsigned - what will fail

<ubl9fv$3prfv$4@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27850&group=comp.lang.c#27850

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 16:05:51 +0200
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <ubl9fv$3prfv$4@dont-email.me>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <HI4DM.141794$ftCb.112835@fx34.iad>
<ubilva$3as8c$1@dont-email.me> <%f5DM.670467$AsA.656909@fx18.iad>
<ubj09u$3ckl4$1@dont-email.me> <j%7DM.428704$U3w1.122961@fx09.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 17 Aug 2023 14:05:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="72e8a34b5b2520a4bec7cd465fd473e2";
logging-data="3993087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18RzGHdsD8jY5qsiQElNoPRpqbAzX3+UGM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:kjoGAry/2jQuTUfmtKh0oH6X5bw=
In-Reply-To: <j%7DM.428704$U3w1.122961@fx09.iad>
Content-Language: en-GB
 by: David Brown - Thu, 17 Aug 2023 14:05 UTC

On 16/08/2023 19:50, Scott Lurndal wrote:
> David Brown <david.brown@hesbynett.no> writes:
>> On 16/08/2023 16:43, Scott Lurndal wrote:
>>> David Brown <david.brown@hesbynett.no> writes:
>>>> On 16/08/2023 16:05, Scott Lurndal wrote:
>>>>> David Brown <david.brown@hesbynett.no> writes:
>>>>>> On 16/08/2023 14:31, Bart wrote:
>>>>>>> On 16/08/2023 07:53, David Brown wrote:
>>>>>>>
>>>>>>>> Just to be clear about this in case anyone wonders why you wrote that
>>>>>>>> - plain "char" can be signed or unsigned, depending on the platform.
>>>>>>>> Older platforms (including x86) tend to have plain char as signed,
>>>>>>>> while more modern ABIs are usually unsigned.
>>>>>>>>
>>>>>>>> It is, of course, a terrible idea to do any kind of arithmetic or hold
>>>>>>>> numbers in plain char - use them for 7-bit ASCII characters only.  For
>>>>>>>> anything with numbers, use "signed char", "unsigned char", or (better,
>>>>>>>> IMHO) appropriate <stdint.h> types when you need a small integer type.
>>>>>>>
>>>>>>> Unfortunately, in C, string literals have type char*, and char* strings
>>>>>>> are encountered everywhere, where they can store ASCII, extended ASCII
>>>>>>> of various kinds, or UTF8.
>>>>>>>
>>>>>>> But you frequently need to manipulate individual character codes.
>>>>>>
>>>>>> It's quite rare to have to manipulate characters individually, other
>>>>>> than perhaps comparing them to character constants. Certainly general
>>>>>> arithmetic is very rare on characters, with the exception of something
>>>>>> like UTF8 code point extraction.
>>>>>
>>>>> toupper() and tolower() were often implemented using arithmetic
>>>>> on characters in the C locale, but the point stands.
>>>>>
>>>>
>>>> Surely that would be logical instructions (x &= ~0x20, or x |= 0x20)
>>>> rather than arithmetic instructions? But I wouldn't do logical
>>>> operations on plain char either! (The C library implementation can, of
>>>> course, do whatever it likes.)
>>>
>>> Unix v7:
>>> #define isalpha(c) ((_ctype_+1)[c]&(_U|_L))
>>> #define isupper(c) ((_ctype_+1)[c]&_U)
>>> #define islower(c) ((_ctype_+1)[c]&_L)
>>> #define isdigit(c) ((_ctype_+1)[c]&_N)
>>> #define isxdigit(c) ((_ctype_+1)[c]&(_N|_X))
>>> #define isspace(c) ((_ctype_+1)[c]&_S)
>>> #define ispunct(c) ((_ctype_+1)[c]&_P)
>>> #define isalnum(c) ((_ctype_+1)[c]&(_U|_L|_N))
>>> #define isprint(c) ((_ctype_+1)[c]&(_P|_U|_L|_N))
>>> #define iscntrl(c) ((_ctype_+1)[c]&_C)
>>> #define isascii(c) ((unsigned)(c)<=0177)
>>> #define toupper(c) ((c)-'a'+'A')
>>> #define tolower(c) ((c)-'A'+'a')
>>> #define toascii(c) ((c)&0177)
>>>
>>
>> Those "toupper" and "tolower" macros are going to give the wrong result
>> for any argument that is not a lower case or upper case (respectively)
>> ASCII letter.
>
> Which in 1979 when Unix V7 in the wild is why isalpha was used to qualify toupper/lower.

That would not suffice - you'd need isupper() or islower() :

#define useful_tolower(c) isupper((c)) ? tolower((c)) : (c)
#define useful_toupper(c) islower((c)) ? toupper((c)) : (c)

>
>> The C standards require the macros to return the argument
>
> The above header file predated the standard by a number of years.
>

Fair enough. Some things have got better over time!

Re: signed/unsigned - what will fail

<ubla19$3prfv$5@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27852&group=comp.lang.c#27852

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 16:15:05 +0200
Organization: A noiseless patient Spider
Lines: 79
Message-ID: <ubla19$3prfv$5@dont-email.me>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <ubj0pj$3cjsl$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 17 Aug 2023 14:15:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="72e8a34b5b2520a4bec7cd465fd473e2";
logging-data="3993087"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18M4iNbxJDRcqGRLlGEc9cvVMvfSIT5930="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:TYn2XH2Hu+omOrNA7hAR6gbU19g=
Content-Language: en-GB
In-Reply-To: <ubj0pj$3cjsl$4@dont-email.me>
 by: David Brown - Thu, 17 Aug 2023 14:15 UTC

On 16/08/2023 19:25, Bart wrote:
> On 16/08/2023 14:31, David Brown wrote:
>> On 16/08/2023 14:31, Bart wrote:
>>> On 16/08/2023 07:53, David Brown wrote:
>>>
>>>> Just to be clear about this in case anyone wonders why you wrote
>>>> that - plain "char" can be signed or unsigned, depending on the
>>>> platform. Older platforms (including x86) tend to have plain char as
>>>> signed, while more modern ABIs are usually unsigned.
>>>>
>>>> It is, of course, a terrible idea to do any kind of arithmetic or
>>>> hold numbers in plain char - use them for 7-bit ASCII characters
>>>> only.  For anything with numbers, use "signed char", "unsigned
>>>> char", or (better, IMHO) appropriate <stdint.h> types when you need
>>>> a small integer type.
>>>
>>> Unfortunately, in C, string literals have type char*, and char*
>>> strings are encountered everywhere, where they can store ASCII,
>>> extended ASCII of various kinds, or UTF8.
>>>
>>> But you frequently need to manipulate individual character codes.
>>
>> It's quite rare to have to manipulate characters individually, other
>> than perhaps comparing them to character constants.  Certainly general
>> arithmetic is very rare on characters, with the exception of something
>> like UTF8 code point extraction.  Do you have examples where people
>> might reasonably want to perform arithmetic on plain char, that you
>> think occur frequently?
>
> It's just something that will come up:
>
> * Relative compares such as:  c >= 'A'

Agreed (as I mentioned).

>
> * Getting the next character in the alphabet: c + 1 (eg. rot13)

Is that common? I agree it can be found in code, but how frequent is it?

>
> * Turning characters into a number: (c-'0')*10 + (d-'0')

Yes, subtracting or adding '0' is a clear use-case that turns up quite
often.

>
> * Using character codes to index into an array: ++counts[c]

That is a fair point, since "counts[c]" means "*(counts + c)". I'd be
extremely careful of doing this, however, precisely because on some
systems, plain char is signed. It's easy to accidentally try to access
negative indexes. (Of course you have to be careful with any array
access to make sure your indexes are in range.)

>
> * Decoding/encoding of different kinds
>
> * Calculating a hash value from a sequence of characters
>
> Etc.
>
> You can just decree that can you can't do anything with a char values
> except compare two characters for equality.
>

I did not decree anything of the sort. I simply said I don't think
arithmetic on plain char (rather than signed or unsigned char) is very
common, and I don't think it is a good idea. (And I also said
comparisons to character literals are common - I did not restrict that
to equality comparisons, because relative comparisons are common.)

You've given a few more cases when it arithmetic on plain chars might
turn up, so maybe it is more common than I first thought. I still think
it is rarely a good idea, but that's just a matter of opinion.

(As noted before - the chars are of course promoted to int, or
hypothetically unsigned int, before the actual arithmetic is performed.)

Re: signed/unsigned - what will fail

<ublrul$3srf9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=27868&group=comp.lang.c#27868

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: signed/unsigned - what will fail
Date: Thu, 17 Aug 2023 21:20:53 +0200
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <ublrul$3srf9$1@dont-email.me>
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
<ubhrot$37a4c$1@dont-email.me> <ubifj9$39v7p$1@dont-email.me>
<ubij3o$3afvd$1@dont-email.me> <874jky2jvm.fsf@fatphil.org>
<V6176aqfRxbq1pWTx@bongo-ra.co> <Q3ZGZO0rTkDNfg8TU@bongo-ra.co>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 17 Aug 2023 19:20:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="622501db6030bf2b285029c66825188f";
logging-data="4091369"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lxq/zFsK9xqmbLLQiHRyt1uqZ/xwApgc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:kX87JzH3Bl1HYz3cSebGRI6s3xE=
Content-Language: en-GB
In-Reply-To: <Q3ZGZO0rTkDNfg8TU@bongo-ra.co>
 by: David Brown - Thu, 17 Aug 2023 19:20 UTC

On 17/08/2023 10:51, Spiros Bousbouras wrote:
> On Thu, 17 Aug 2023 08:17:52 -0000 (UTC)
> Spiros Bousbouras <spibou@gmail.com> wrote:
>> On Thu, 17 Aug 2023 10:44:29 +0300
>> Phil Carmody <pc+usenet@asdf.org> wrote:
>>> David Brown <david.brown@hesbynett.no> writes:
>>>> It's quite rare to have to manipulate characters individually, other
>>>> than perhaps comparing them to character constants. Certainly general
>>>> arithmetic is very rare on characters, with the exception of something
>>>> like UTF8 code point extraction. Do you have examples where people
>>>> might reasonably want to perform arithmetic on plain char, that you
>>>> think occur frequently?
>>>>
>>>> I think it is entirely appropriate to use "char" for characters (and
>>>> const char* for immutable strings). But I don't think it is
>>>> appropriate for any kind of arithmetic.
>>>
>>> How would you hash a string (for example for insertion in a hash table)
>>> without arithmetic?
>>
>> You would cast each element of the string to an unsigned integer type
>> which won't get promoted to a signed type ; so unsigned int at least.
>> And then you would feed your hash function the unsigned integers. How
>> wide these would need to be depends on how many bits the hash values
>> are supposed to have.

Or you would use unsigned char - viewing the string as a block of
memory. (The unsigned char would then be promoted or converted - I
would convert it to an unsigned int type.)

>
> Come to think of it , it has been discussed several times on this group
> whether wraparound arithmetic is ever useful. It is useful for hashing and
> also for pseudorandom number generators. But for such applications , using
> non negative integers is probably preferable.
>

Agreed.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor