Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Never make any mistaeks. -- Anonymous, in a mail discussion about to a kernel bug report


devel / comp.lang.c / 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
signed/unsigned - what will fail

<21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1a8e:b0:40f:d692:ef9a with SMTP id s14-20020a05622a1a8e00b0040fd692ef9amr132109qtc.7.1692107459004;
Tue, 15 Aug 2023 06:50:59 -0700 (PDT)
X-Received: by 2002:a63:8f17:0:b0:564:514e:ce88 with SMTP id
n23-20020a638f17000000b00564514ece88mr2442503pgd.0.1692107458751; Tue, 15 Aug
2023 06:50:58 -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: Tue, 15 Aug 2023 06:50:58 -0700 (PDT)
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.176; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.176
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
Subject: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Tue, 15 Aug 2023 13:50:58 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1425
 by: fir - Tue, 15 Aug 2023 13:50 UTC

im not sure if im a fan of division signed/unsigned
(for example maybe there are cases where you dont care
and in such case treat given int as both signed and unsigned
(as it kinda is)

im not stating hovever to define 3 tates signed, unsigned, and
dontcare or just remove signed unsigned or what else - becouse i dont
know, i dont understand it enough well

but asume i use dont care (and always write just "int"):
what will exactly fail?

Re: signed/unsigned - what will fail

<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1808:b0:403:aa87:d220 with SMTP id t8-20020a05622a180800b00403aa87d220mr128233qtc.0.1692107947729;
Tue, 15 Aug 2023 06:59:07 -0700 (PDT)
X-Received: by 2002:a05:6a00:3928:b0:686:df16:f887 with SMTP id
fh40-20020a056a00392800b00686df16f887mr6354170pfb.6.1692107947198; Tue, 15
Aug 2023 06:59:07 -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: Tue, 15 Aug 2023 06:59:06 -0700 (PDT)
In-Reply-To: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.176; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.176
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Tue, 15 Aug 2023 13:59:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1943
 by: fir - Tue, 15 Aug 2023 13:59 UTC

wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> im not sure if im a fan of division signed/unsigned
> (for example maybe there are cases where you dont care
> and in such case treat given int as both signed and unsigned
> (as it kinda is)
>
> im not stating hovever to define 3 tates signed, unsigned, and
> dontcare or just remove signed unsigned or what else - becouse i dont
> know, i dont understand it enough well
>
> but asume i use dont care (and always write just "int"):
> what will exactly fail?

im not sure but probably could assume that additions and subtractions are safe,
but im not sure:

seay

char a = 200, b= 200;

int c = a+b; //is it 400?

int d = a*b; //what with that?

Re: signed/unsigned - what will fail

<58c59847-321e-4174-9bd0-255a3159d220n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:6501:b0:76d:fe8:1b03 with SMTP id qb1-20020a05620a650100b0076d0fe81b03mr128443qkn.15.1692108190464;
Tue, 15 Aug 2023 07:03:10 -0700 (PDT)
X-Received: by 2002:a05:6a00:1825:b0:686:251a:7551 with SMTP id
y37-20020a056a00182500b00686251a7551mr6776083pfa.2.1692108189903; Tue, 15 Aug
2023 07:03:09 -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: Tue, 15 Aug 2023 07:03:09 -0700 (PDT)
In-Reply-To: <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.176; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.176
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com> <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <58c59847-321e-4174-9bd0-255a3159d220n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Tue, 15 Aug 2023 14:03:10 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2488
 by: fir - Tue, 15 Aug 2023 14:03 UTC

wtorek, 15 sierpnia 2023 o 15:59:15 UTC+2 fir napisał(a):
> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> > im not sure if im a fan of division signed/unsigned
> > (for example maybe there are cases where you dont care
> > and in such case treat given int as both signed and unsigned
> > (as it kinda is)
> >
> > im not stating hovever to define 3 tates signed, unsigned, and
> > dontcare or just remove signed unsigned or what else - becouse i dont
> > know, i dont understand it enough well
> >
> > but asume i use dont care (and always write just "int"):
> > what will exactly fail?
> im not sure but probably could assume that additions and subtractions are safe,
> but im not sure:
>
> seay
>
> char a = 200, b= 200;
>
> int c = a+b; //is it 400?
>
> int d = a*b; //what with that?

i would also like probably to insight the thesis that programming language like c should be donte maybe thsi way that maybe thsi kind of expresions should work like int and char woudl be of class "dontcare" i mean possibly giving proper results for a=b=-20, and a=b=200; (and maybe even a=b=-200) but i dont 'inspected' it all

Re: signed/unsigned - what will fail

<89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1a81:b0:405:47dd:2777 with SMTP id s1-20020a05622a1a8100b0040547dd2777mr141395qtc.5.1692110699147;
Tue, 15 Aug 2023 07:44:59 -0700 (PDT)
X-Received: by 2002:a63:8c50:0:b0:55b:24a0:584c with SMTP id
q16-20020a638c50000000b0055b24a0584cmr2225923pgn.4.1692110698703; Tue, 15 Aug
2023 07:44:58 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!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: Tue, 15 Aug 2023 07:44:58 -0700 (PDT)
In-Reply-To: <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.50.190.130; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 84.50.190.130
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com> <7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Tue, 15 Aug 2023 14:44:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2502
 by: Öö Tiib - Tue, 15 Aug 2023 14:44 UTC

On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> > im not sure if im a fan of division signed/unsigned
> > (for example maybe there are cases where you dont care
> > and in such case treat given int as both signed and unsigned
> > (as it kinda is)
> >
> > im not stating hovever to define 3 tates signed, unsigned, and
> > dontcare or just remove signed unsigned or what else - becouse i dont
> > know, i dont understand it enough well
> >
> > but asume i use dont care (and always write just "int"):
> > what will exactly fail?
> im not sure but probably could assume that additions and subtractions are safe,
> but im not sure:
>
> seay
>
> char a = 200, b= 200;
>
You contradict your "and always write just "int"" I see clearly char there.

Do you turn off warnings on your compilers? With gcc you get most likely
something like: "warning: overflow in conversion from 'int' to 'char' changes
value from '200' to '-56' [-Woverflow]"

> int c = a+b; //is it 400?

Can be, but it is more likely -112.

>
> int d = a*b; //what with that?

Can be 40000, 3136, -25536, what is your point?

Re: signed/unsigned - what will fail

<6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:4b23:0:b0:63f:7a4f:9186 with SMTP id s3-20020ad44b23000000b0063f7a4f9186mr149201qvw.0.1692111673825;
Tue, 15 Aug 2023 08:01:13 -0700 (PDT)
X-Received: by 2002:a63:3d0f:0:b0:565:e682:f975 with SMTP id
k15-20020a633d0f000000b00565e682f975mr199157pga.0.1692111673255; Tue, 15 Aug
2023 08:01:13 -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: Tue, 15 Aug 2023 08:01:12 -0700 (PDT)
In-Reply-To: <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.241; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.241
References: <21d1ef97-8620-4115-b412-7279e0ef4d6bn@googlegroups.com>
<7ffec8c7-1b4c-4c3c-9342-daed7af19dabn@googlegroups.com> <89f530cb-dd82-46f9-9567-a1f81e55d239n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Tue, 15 Aug 2023 15:01:13 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3070
 by: fir - Tue, 15 Aug 2023 15:01 UTC

wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
> On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
> > wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> > > im not sure if im a fan of division signed/unsigned
> > > (for example maybe there are cases where you dont care
> > > and in such case treat given int as both signed and unsigned
> > > (as it kinda is)
> > >
> > > im not stating hovever to define 3 tates signed, unsigned, and
> > > dontcare or just remove signed unsigned or what else - becouse i dont
> > > know, i dont understand it enough well
> > >
> > > but asume i use dont care (and always write just "int"):
> > > what will exactly fail?
> > im not sure but probably could assume that additions and subtractions are safe,
> > but im not sure:
> >
> > seay
> >
> > char a = 200, b= 200;
> >
> You contradict your "and always write just "int"" I see clearly char there.
>
> Do you turn off warnings on your compilers? With gcc you get most likely
> something like: "warning: overflow in conversion from 'int' to 'char' changes
> value from '200' to '-56' [-Woverflow]"
> > int c = a+b; //is it 400?
> Can be, but it is more likely -112.
> >
> > int d = a*b; //what with that?
> Can be 40000, 3136, -25536, what is your point?

it cant be 2 or 3 at once it is one of it..

points may be many but im close to think that such "expresiion" shouldgenerally 'carry'
a real value this way if

int a = -200, b=-200;
int c = a*b ; c should be 40000 and so on

i think possibly classes like signed unsigned maybe should be more use for storage arrays not much in normal calculations

Re: signed/unsigned - what will fail

<c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5581:0:b0:63c:f17e:ccd0 with SMTP id f1-20020ad45581000000b0063cf17eccd0mr137049qvx.8.1692118135273;
Tue, 15 Aug 2023 09:48:55 -0700 (PDT)
X-Received: by 2002:a17:902:ecc2:b0:1bb:ad19:6b77 with SMTP id
a2-20020a170902ecc200b001bbad196b77mr934047plh.2.1692118135047; Tue, 15 Aug
2023 09:48:55 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.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: Tue, 15 Aug 2023 09:48:54 -0700 (PDT)
In-Reply-To: <6fcfcd10-82e7-4ecb-8bec-e6292ff73322n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=84.50.190.130; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 84.50.190.130
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Tue, 15 Aug 2023 16:48:55 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3663
 by: Öö Tiib - Tue, 15 Aug 2023 16:48 UTC

On Tuesday, 15 August 2023 at 18:01:23 UTC+3, fir wrote:
> wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
> > On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
> > > wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> > > > im not sure if im a fan of division signed/unsigned
> > > > (for example maybe there are cases where you dont care
> > > > and in such case treat given int as both signed and unsigned
> > > > (as it kinda is)
> > > >
> > > > im not stating hovever to define 3 tates signed, unsigned, and
> > > > dontcare or just remove signed unsigned or what else - becouse i dont
> > > > know, i dont understand it enough well
> > > >
> > > > but asume i use dont care (and always write just "int"):
> > > > what will exactly fail?
> > > im not sure but probably could assume that additions and subtractions are safe,
> > > but im not sure:
> > >
> > > seay
> > >
> > > char a = 200, b= 200;
> > >
> > You contradict your "and always write just "int"" I see clearly char there.
> >
> > Do you turn off warnings on your compilers? With gcc you get most likely
> > something like: "warning: overflow in conversion from 'int' to 'char' changes
> > value from '200' to '-56' [-Woverflow]"
> > > int c = a+b; //is it 400?
> > Can be, but it is more likely -112.
> > >
> > > int d = a*b; //what with that?
> > Can be 40000, 3136, -25536, what is your point?
>
> it cant be 2 or 3 at once it is one of it..
>
It may cause signed integer overflow on 8 bit or 16 bit embedded system
and that is undefined behavior unless something defines it for said system.

>
> points may be many but im close to think that such "expresiion" shouldgenerally 'carry'
> a real value this way if
>
> int a = -200, b=-200;
> int c = a*b ; c should be 40000 and so on
>
> i think possibly classes like signed unsigned maybe should be more use for storage arrays not much in normal calculations

How so? If on 8 bit microcontroller int has 16 bits of storage with value
range -32768 to 32767 then there are no way how it can be 40000.
It is simply impossible for c to have that value.

Re: signed/unsigned - what will fail

<ubhrot$37a4c$1@dont-email.me>

  copy mid

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

  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: Wed, 16 Aug 2023 08:53:16 +0200
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <ubhrot$37a4c$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 06:53:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="31f88dcb6b6bb39d1a90cf8e0c2a62fe";
logging-data="3385484"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19NDKxDa9JwCLaonz3k2fRPSfyixYl7aO4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:u43rYxpUzPnYCzpuYO1/KbzqYX8=
In-Reply-To: <c7bd3b8e-a9d1-4e38-a4ce-f7697bc2e777n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Wed, 16 Aug 2023 06:53 UTC

On 15/08/2023 18:48, Öö Tiib wrote:
> On Tuesday, 15 August 2023 at 18:01:23 UTC+3, fir wrote:
>> wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
>>> On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
>>>> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
>>>>> im not sure if im a fan of division signed/unsigned
>>>>> (for example maybe there are cases where you dont care
>>>>> and in such case treat given int as both signed and unsigned
>>>>> (as it kinda is)
>>>>>
>>>>> im not stating hovever to define 3 tates signed, unsigned, and
>>>>> dontcare or just remove signed unsigned or what else - becouse i dont
>>>>> know, i dont understand it enough well
>>>>>
>>>>> but asume i use dont care (and always write just "int"):
>>>>> what will exactly fail?
>>>> im not sure but probably could assume that additions and subtractions are safe,
>>>> but im not sure:
>>>>
>>>> seay
>>>>
>>>> char a = 200, b= 200;
>>>>
>>> You contradict your "and always write just "int"" I see clearly char there.
>>>
>>> Do you turn off warnings on your compilers? With gcc you get most likely
>>> something like: "warning: overflow in conversion from 'int' to 'char' changes
>>> value from '200' to '-56' [-Woverflow]"
>>>> int c = a+b; //is it 400?
>>> Can be, but it is more likely -112.

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.

So after "char a = 200;", the value in "a" depends on the target's ABI.
(Enabling warnings on the compiler is always a good idea!)

>>>>
>>>> int d = a*b; //what with that?
>>> Can be 40000, 3136, -25536, what is your point?
>>
>> it cant be 2 or 3 at once it is one of it..

If plain char is signed on the target, then "d" will always be 3136.

If plain char is unsigned and int is bigger than 16 bit (generally 32
bit) on the target, then "d" will always be 40000.

If plain char is unsigned and int is 16-bit, then there is an arithmetic
overflow in the signed int multiplication - that's undefined behaviour,
and there's no limit to what can go wrong, including the compiler
generating code that treats the result as 2 or 3 of these values.
Often, it will appear to be -25536 - but that is not guaranteed or
reliable in any way (without specific compiler flags or documentation).

(I know you, Öö, know this - but fir may be less sure.)

>>
> It may cause signed integer overflow on 8 bit or 16 bit embedded system
> and that is undefined behavior unless something defines it for said system.
>
>>
>> points may be many but im close to think that such "expresiion" shouldgenerally 'carry'
>> a real value this way if
>>
>> int a = -200, b=-200;
>> int c = a*b ; c should be 40000 and so on
>>
>> i think possibly classes like signed unsigned maybe should be more use for storage arrays not much in normal calculations
>
> How so? If on 8 bit microcontroller int has 16 bits of storage with value
> range -32768 to 32767 then there are no way how it can be 40000.
> It is simply impossible for c to have that value.

Re: signed/unsigned - what will fail

<aedc8f63-5638-4d24-a116-594dc63c8fa4n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1882:b0:40d:4c6:bcea with SMTP id v2-20020a05622a188200b0040d04c6bceamr11137qtc.3.1692169347382;
Wed, 16 Aug 2023 00:02:27 -0700 (PDT)
X-Received: by 2002:a17:902:ecc2:b0:1b7:edcd:8dcf with SMTP id
a2-20020a170902ecc200b001b7edcd8dcfmr401293plh.4.1692169346855; Wed, 16 Aug
2023 00:02:26 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!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 00:02:26 -0700 (PDT)
In-Reply-To: <ubhrot$37a4c$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:a6:dd70:dbcb:58c;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:a6:dd70:dbcb:58c
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <aedc8f63-5638-4d24-a116-594dc63c8fa4n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 16 Aug 2023 07:02:27 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Malcolm McLean - Wed, 16 Aug 2023 07:02 UTC

On Wednesday, 16 August 2023 at 07:53:32 UTC+1, David Brown wrote:
> On 15/08/2023 18:48, Öö Tiib wrote:
> > On Tuesday, 15 August 2023 at 18:01:23 UTC+3, fir wrote:
> >> wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
> >>> On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
> >>>> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> >>>>> im not sure if im a fan of division signed/unsigned
> >>>>> (for example maybe there are cases where you dont care
> >>>>> and in such case treat given int as both signed and unsigned
> >>>>> (as it kinda is)
> >>>>>
> >>>>> im not stating hovever to define 3 tates signed, unsigned, and
> >>>>> dontcare or just remove signed unsigned or what else - becouse i dont
> >>>>> know, i dont understand it enough well
> >>>>>
> >>>>> but asume i use dont care (and always write just "int"):
> >>>>> what will exactly fail?
> >>>> im not sure but probably could assume that additions and subtractions are safe,
> >>>> but im not sure:
> >>>>
> >>>> seay
> >>>>
> >>>> char a = 200, b= 200;
> >>>>
> >>> You contradict your "and always write just "int"" I see clearly char there.
> >>>
> >>> Do you turn off warnings on your compilers? With gcc you get most likely
> >>> something like: "warning: overflow in conversion from 'int' to 'char' changes
> >>> value from '200' to '-56' [-Woverflow]"
> >>>> int c = a+b; //is it 400?
> >>> Can be, but it is more likely -112.
> 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.
>
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.

Re: signed/unsigned - what will fail

<ubiahg$394g8$4@dont-email.me>

  copy mid

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

  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: Wed, 16 Aug 2023 13:05:20 +0200
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <ubiahg$394g8$4@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>
<aedc8f63-5638-4d24-a116-594dc63c8fa4n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 11:05:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="31f88dcb6b6bb39d1a90cf8e0c2a62fe";
logging-data="3445256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iCYyGP10K7pKzqA7RMKSL1js8tRQn2ik="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:LklapG4sFP3tXf0GltAxzZvMt2M=
Content-Language: en-GB
In-Reply-To: <aedc8f63-5638-4d24-a116-594dc63c8fa4n@googlegroups.com>
 by: David Brown - Wed, 16 Aug 2023 11:05 UTC

On 16/08/2023 09:02, Malcolm McLean wrote:
> On Wednesday, 16 August 2023 at 07:53:32 UTC+1, David Brown wrote:
>> On 15/08/2023 18:48, Öö Tiib wrote:
>>> On Tuesday, 15 August 2023 at 18:01:23 UTC+3, fir wrote:
>>>> wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
>>>>> On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
>>>>>> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
>>>>>>> im not sure if im a fan of division signed/unsigned
>>>>>>> (for example maybe there are cases where you dont care
>>>>>>> and in such case treat given int as both signed and unsigned
>>>>>>> (as it kinda is)
>>>>>>>
>>>>>>> im not stating hovever to define 3 tates signed, unsigned, and
>>>>>>> dontcare or just remove signed unsigned or what else - becouse i dont
>>>>>>> know, i dont understand it enough well
>>>>>>>
>>>>>>> but asume i use dont care (and always write just "int"):
>>>>>>> what will exactly fail?
>>>>>> im not sure but probably could assume that additions and subtractions are safe,
>>>>>> but im not sure:
>>>>>>
>>>>>> seay
>>>>>>
>>>>>> char a = 200, b= 200;
>>>>>>
>>>>> You contradict your "and always write just "int"" I see clearly char there.
>>>>>
>>>>> Do you turn off warnings on your compilers? With gcc you get most likely
>>>>> something like: "warning: overflow in conversion from 'int' to 'char' changes
>>>>> value from '200' to '-56' [-Woverflow]"
>>>>>> int c = a+b; //is it 400?
>>>>> Can be, but it is more likely -112.
>> 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.
>>
> 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.

Conversion from plain char to unsigned char will always be safe and
well-defined, regardless of the signedness of plain char. And it is
always safe to access plain char data through an unsigned char pointer.
Given that string literals are treated as char array (unless you have an
encoding prefix for wide characters of some kind), using plain char
seems entirely reasonable. But "const char *" would be vastly better.

(The conversion from unsigned char to plain char is implementation
dependent, but I know of no platforms where it will not work in the
simple and obvious way.)

Re: signed/unsigned - what will fail

<ubifj9$39v7p$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.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 13:31:37 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <ubifj9$39v7p$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 12:31:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="17f8aedb09110eed4ec1c7adfd187d70";
logging-data="3472633"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1823KpdttqHYXTmcg9O4vRIuGHdDvlb8Z0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:r8txdGsEZCmeTqPMJCGY4BCcQOo=
In-Reply-To: <ubhrot$37a4c$1@dont-email.me>
 by: Bart - Wed, 16 Aug 2023 12:31 UTC

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.

Re: signed/unsigned - what will fail

<ubij3o$3afvd$1@dont-email.me>

  copy mid

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

  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: Wed, 16 Aug 2023 15:31:35 +0200
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <ubij3o$3afvd$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 13:31:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="31f88dcb6b6bb39d1a90cf8e0c2a62fe";
logging-data="3489773"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/twA4+Zs8ne3hDjC30qTAG+m+5Jtgxaok="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:v+7GmovGUq5oIjnNXKMBLFNzMrc=
In-Reply-To: <ubifj9$39v7p$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Wed, 16 Aug 2023 13:31 UTC

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.

Re: signed/unsigned - what will fail

<HI4DM.141794$ftCb.112835@fx34.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx34.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: signed/unsigned - what will fail
Newsgroups: comp.lang.c
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>
Lines: 29
Message-ID: <HI4DM.141794$ftCb.112835@fx34.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 16 Aug 2023 14:05:27 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 16 Aug 2023 14:05:27 GMT
X-Received-Bytes: 2367
 by: Scott Lurndal - Wed, 16 Aug 2023 14:05 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.

toupper() and tolower() were often implemented using arithmetic
on characters in the C locale, but the point stands.

Re: signed/unsigned - what will fail

<ubilva$3as8c$1@dont-email.me>

  copy mid

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

  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: Wed, 16 Aug 2023 16:20:26 +0200
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <ubilva$3as8c$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> <HI4DM.141794$ftCb.112835@fx34.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 14:20:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="31f88dcb6b6bb39d1a90cf8e0c2a62fe";
logging-data="3502348"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18h5jfHpW03QV0qt1AW9zDpSQSiqrkLtlk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.9.0
Cancel-Lock: sha1:wIhayeygz6TONd743Te/CyKZ+0s=
Content-Language: en-GB
In-Reply-To: <HI4DM.141794$ftCb.112835@fx34.iad>
 by: David Brown - Wed, 16 Aug 2023 14:20 UTC

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.)

Re: signed/unsigned - what will fail

<9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:649:b0:403:e8a7:bd9b with SMTP id a9-20020a05622a064900b00403e8a7bd9bmr29000qtb.11.1692196508015;
Wed, 16 Aug 2023 07:35:08 -0700 (PDT)
X-Received: by 2002:a17:902:f950:b0:1b5:147f:d8d1 with SMTP id
kx16-20020a170902f95000b001b5147fd8d1mr636186plb.3.1692196507651; Wed, 16 Aug
2023 07:35:07 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.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 07:35:06 -0700 (PDT)
In-Reply-To: <ubij3o$3afvd$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=81.143.231.9; posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 81.143.231.9
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 16 Aug 2023 14:35:08 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3279
 by: Malcolm McLean - Wed, 16 Aug 2023 14:35 UTC

On Wednesday, 16 August 2023 at 14:31:51 UTC+1, 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?
>
> 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

strchr("0123456789", ch);

to convert from character to digit. But people like efficiency.

Re: signed/unsigned - what will fail

<%f5DM.670467$AsA.656909@fx18.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: signed/unsigned - what will fail
Newsgroups: comp.lang.c
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> <HI4DM.141794$ftCb.112835@fx34.iad> <ubilva$3as8c$1@dont-email.me>
Lines: 64
Message-ID: <%f5DM.670467$AsA.656909@fx18.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 16 Aug 2023 14:43:07 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 16 Aug 2023 14:43:07 GMT
X-Received-Bytes: 3703
 by: Scott Lurndal - Wed, 16 Aug 2023 14:43 UTC

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)

Unixware 2.01:

#define isascii(c) (!((c) & ~0177))
#define toascii(c) ((c) & 0177)

#if defined(_XOPEN_SOURCE) || (__STDC__ == 0 \
&& !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE))
#define _toupper(c) ((__ctype + 258)[c])
#define _tolower(c) ((__ctype + 258)[c])

>

Re: signed/unsigned - what will fail

<88a6f46b-d2aa-49ff-a60f-36448e126af3n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:8606:0:b0:76a:f46f:a04f with SMTP id i6-20020a378606000000b0076af46fa04fmr23192qkd.6.1692198877117;
Wed, 16 Aug 2023 08:14:37 -0700 (PDT)
X-Received: by 2002:a05:6a00:2d10:b0:666:e42c:d5ec with SMTP id
fa16-20020a056a002d1000b00666e42cd5ecmr1036832pfb.3.1692198876832; Wed, 16
Aug 2023 08:14:36 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.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 08:14:36 -0700 (PDT)
In-Reply-To: <ubhrot$37a4c$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.222; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.222
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <88a6f46b-d2aa-49ff-a60f-36448e126af3n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 15:14:37 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5275
 by: fir - Wed, 16 Aug 2023 15:14 UTC

środa, 16 sierpnia 2023 o 08:53:32 UTC+2 David Brown napisał(a):
> On 15/08/2023 18:48, Öö Tiib wrote:
> > On Tuesday, 15 August 2023 at 18:01:23 UTC+3, fir wrote:
> >> wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
> >>> On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
> >>>> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> >>>>> im not sure if im a fan of division signed/unsigned
> >>>>> (for example maybe there are cases where you dont care
> >>>>> and in such case treat given int as both signed and unsigned
> >>>>> (as it kinda is)
> >>>>>
> >>>>> im not stating hovever to define 3 tates signed, unsigned, and
> >>>>> dontcare or just remove signed unsigned or what else - becouse i dont
> >>>>> know, i dont understand it enough well
> >>>>>
> >>>>> but asume i use dont care (and always write just "int"):
> >>>>> what will exactly fail?
> >>>> im not sure but probably could assume that additions and subtractions are safe,
> >>>> but im not sure:
> >>>>
> >>>> seay
> >>>>
> >>>> char a = 200, b= 200;
> >>>>
> >>> You contradict your "and always write just "int"" I see clearly char there.
> >>>
> >>> Do you turn off warnings on your compilers? With gcc you get most likely
> >>> something like: "warning: overflow in conversion from 'int' to 'char' changes
> >>> value from '200' to '-56' [-Woverflow]"
> >>>> int c = a+b; //is it 400?
> >>> Can be, but it is more likely -112.
> 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.
>
> So after "char a = 200;", the value in "a" depends on the target's ABI.
> (Enabling warnings on the compiler is always a good idea!)
> >>>>
> >>>> int d = a*b; //what with that?
> >>> Can be 40000, 3136, -25536, what is your point?
> >>
> >> it cant be 2 or 3 at once it is one of it..
> If plain char is signed on the target, then "d" will always be 3136.
>
> If plain char is unsigned and int is bigger than 16 bit (generally 32
> bit) on the target, then "d" will always be 40000.
>
> If plain char is unsigned and int is 16-bit, then there is an arithmetic
> overflow in the signed int multiplication - that's undefined behaviour,
> and there's no limit to what can go wrong, including the compiler
> generating code that treats the result as 2 or 3 of these values.
> Often, it will appear to be -25536 - but that is not guaranteed or
> reliable in any way (without specific compiler flags or documentation).
>
> (I know you, Öö, know this - but fir may be less sure.)

i told some tiem ago i learned c totally in 2014 or something (talking abut statement c is said by someone to be simple) - as to this signed unsigned piece of mess i dont know this...
though i got some idea - it seem to me that general arithmetoc should be done nearly always on signed - as unsigned types may be said are not to be to do arithmetic maybe, they are for logical/bytelike types for more bit operations

thsi maybe signed/unsigned is kinda misleading suggesting both are something liek arithmetic types with two wariants, where arithmetic is int

Re: signed/unsigned - what will fail

<1b45016f-bb5b-430e-a5d9-47f1b61fe5ecn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:9c3:b0:649:aa62:1ef0 with SMTP id dp3-20020a05621409c300b00649aa621ef0mr150qvb.2.1692200099898;
Wed, 16 Aug 2023 08:34:59 -0700 (PDT)
X-Received: by 2002:a17:902:d50e:b0:1af:f80f:185d with SMTP id
b14-20020a170902d50e00b001aff80f185dmr932166plg.4.1692200099398; Wed, 16 Aug
2023 08:34:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.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 08:34:58 -0700 (PDT)
In-Reply-To: <88a6f46b-d2aa-49ff-a60f-36448e126af3n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.222; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.222
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> <88a6f46b-d2aa-49ff-a60f-36448e126af3n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <1b45016f-bb5b-430e-a5d9-47f1b61fe5ecn@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 15:34:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 6093
 by: fir - Wed, 16 Aug 2023 15:34 UTC

środa, 16 sierpnia 2023 o 17:14:44 UTC+2 fir napisał(a):
> środa, 16 sierpnia 2023 o 08:53:32 UTC+2 David Brown napisał(a):
> > On 15/08/2023 18:48, Öö Tiib wrote:
> > > On Tuesday, 15 August 2023 at 18:01:23 UTC+3, fir wrote:
> > >> wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
> > >>> On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
> > >>>> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> > >>>>> im not sure if im a fan of division signed/unsigned
> > >>>>> (for example maybe there are cases where you dont care
> > >>>>> and in such case treat given int as both signed and unsigned
> > >>>>> (as it kinda is)
> > >>>>>
> > >>>>> im not stating hovever to define 3 tates signed, unsigned, and
> > >>>>> dontcare or just remove signed unsigned or what else - becouse i dont
> > >>>>> know, i dont understand it enough well
> > >>>>>
> > >>>>> but asume i use dont care (and always write just "int"):
> > >>>>> what will exactly fail?
> > >>>> im not sure but probably could assume that additions and subtractions are safe,
> > >>>> but im not sure:
> > >>>>
> > >>>> seay
> > >>>>
> > >>>> char a = 200, b= 200;
> > >>>>
> > >>> You contradict your "and always write just "int"" I see clearly char there.
> > >>>
> > >>> Do you turn off warnings on your compilers? With gcc you get most likely
> > >>> something like: "warning: overflow in conversion from 'int' to 'char' changes
> > >>> value from '200' to '-56' [-Woverflow]"
> > >>>> int c = a+b; //is it 400?
> > >>> Can be, but it is more likely -112.
> > 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.
> >
> > So after "char a = 200;", the value in "a" depends on the target's ABI.
> > (Enabling warnings on the compiler is always a good idea!)
> > >>>>
> > >>>> int d = a*b; //what with that?
> > >>> Can be 40000, 3136, -25536, what is your point?
> > >>
> > >> it cant be 2 or 3 at once it is one of it..
> > If plain char is signed on the target, then "d" will always be 3136.
> >
> > If plain char is unsigned and int is bigger than 16 bit (generally 32
> > bit) on the target, then "d" will always be 40000.
> >
> > If plain char is unsigned and int is 16-bit, then there is an arithmetic
> > overflow in the signed int multiplication - that's undefined behaviour,
> > and there's no limit to what can go wrong, including the compiler
> > generating code that treats the result as 2 or 3 of these values.
> > Often, it will appear to be -25536 - but that is not guaranteed or
> > reliable in any way (without specific compiler flags or documentation).
> >
> > (I know you, Öö, know this - but fir may be less sure.)
> i told some tiem ago i learned c totally in 2014 or something (talking abut statement c is said by someone to be simple) - as to this signed unsigned piece of mess i dont know this...
> though i got some idea - it seem to me that general arithmetoc should be done nearly always on signed - as unsigned types may be said are not to be to do arithmetic maybe, they are for logical/bytelike types for more bit operations
>
> thsi maybe signed/unsigned is kinda misleading suggesting both are something liek arithmetic types with two wariants, where arithmetic is int

other part of thought is in fact people can say when saying say char as
a thing that is not "signed char" and "unsigned char" or "negative unsigned char" (with values -1 to -256 ? or 0 to -255?) but some abstract union of this

and the question is if use this abstract union is not wisest

becouse when someone says write char a =200 (when char on given platform is signed) and char b =200 then the question is if
int c = a*b; shouldnt be in fact 40000

should it or should not?

Re: signed/unsigned - what will fail

<7f816bce-d897-453a-bc5e-820b2e5bf8e4n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5f11:0:b0:40f:c807:f5f8 with SMTP id x17-20020ac85f11000000b0040fc807f5f8mr28841qta.10.1692200939695;
Wed, 16 Aug 2023 08:48:59 -0700 (PDT)
X-Received: by 2002:a17:903:11c3:b0:1bc:5182:1da2 with SMTP id
q3-20020a17090311c300b001bc51821da2mr852365plh.11.1692200939139; Wed, 16 Aug
2023 08:48:59 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!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 08:48:58 -0700 (PDT)
In-Reply-To: <1b45016f-bb5b-430e-a5d9-47f1b61fe5ecn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.222; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.222
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> <88a6f46b-d2aa-49ff-a60f-36448e126af3n@googlegroups.com>
<1b45016f-bb5b-430e-a5d9-47f1b61fe5ecn@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <7f816bce-d897-453a-bc5e-820b2e5bf8e4n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 15:48:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Wed, 16 Aug 2023 15:48 UTC

środa, 16 sierpnia 2023 o 17:35:09 UTC+2 fir napisał(a):
> środa, 16 sierpnia 2023 o 17:14:44 UTC+2 fir napisał(a):
> > środa, 16 sierpnia 2023 o 08:53:32 UTC+2 David Brown napisał(a):
> > > On 15/08/2023 18:48, Öö Tiib wrote:
> > > > On Tuesday, 15 August 2023 at 18:01:23 UTC+3, fir wrote:
> > > >> wtorek, 15 sierpnia 2023 o 16:45:07 UTC+2 Öö Tiib napisał(a):
> > > >>> On Tuesday, 15 August 2023 at 16:59:15 UTC+3, fir wrote:
> > > >>>> wtorek, 15 sierpnia 2023 o 15:51:07 UTC+2 fir napisał(a):
> > > >>>>> im not sure if im a fan of division signed/unsigned
> > > >>>>> (for example maybe there are cases where you dont care
> > > >>>>> and in such case treat given int as both signed and unsigned
> > > >>>>> (as it kinda is)
> > > >>>>>
> > > >>>>> im not stating hovever to define 3 tates signed, unsigned, and
> > > >>>>> dontcare or just remove signed unsigned or what else - becouse i dont
> > > >>>>> know, i dont understand it enough well
> > > >>>>>
> > > >>>>> but asume i use dont care (and always write just "int"):
> > > >>>>> what will exactly fail?
> > > >>>> im not sure but probably could assume that additions and subtractions are safe,
> > > >>>> but im not sure:
> > > >>>>
> > > >>>> seay
> > > >>>>
> > > >>>> char a = 200, b= 200;
> > > >>>>
> > > >>> You contradict your "and always write just "int"" I see clearly char there.
> > > >>>
> > > >>> Do you turn off warnings on your compilers? With gcc you get most likely
> > > >>> something like: "warning: overflow in conversion from 'int' to 'char' changes
> > > >>> value from '200' to '-56' [-Woverflow]"
> > > >>>> int c = a+b; //is it 400?
> > > >>> Can be, but it is more likely -112.
> > > 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..
> > >
> > > So after "char a = 200;", the value in "a" depends on the target's ABI.
> > > (Enabling warnings on the compiler is always a good idea!)
> > > >>>>
> > > >>>> int d = a*b; //what with that?
> > > >>> Can be 40000, 3136, -25536, what is your point?
> > > >>
> > > >> it cant be 2 or 3 at once it is one of it..
> > > If plain char is signed on the target, then "d" will always be 3136.
> > >
> > > If plain char is unsigned and int is bigger than 16 bit (generally 32
> > > bit) on the target, then "d" will always be 40000.
> > >
> > > If plain char is unsigned and int is 16-bit, then there is an arithmetic
> > > overflow in the signed int multiplication - that's undefined behaviour,
> > > and there's no limit to what can go wrong, including the compiler
> > > generating code that treats the result as 2 or 3 of these values.
> > > Often, it will appear to be -25536 - but that is not guaranteed or
> > > reliable in any way (without specific compiler flags or documentation).
> > >
> > > (I know you, Öö, know this - but fir may be less sure.)
> > i told some tiem ago i learned c totally in 2014 or something (talking abut statement c is said by someone to be simple) - as to this signed unsigned piece of mess i dont know this...
> > though i got some idea - it seem to me that general arithmetoc should be done nearly always on signed - as unsigned types may be said are not to be to do arithmetic maybe, they are for logical/bytelike types for more bit operations
> >
> > thsi maybe signed/unsigned is kinda misleading suggesting both are something liek arithmetic types with two wariants, where arithmetic is int
> other part of thought is in fact people can say when saying say char as
> a thing that is not "signed char" and "unsigned char" or "negative unsigned char" (with values -1 to -256 ? or 0 to -255?) but some abstract union of this
>
> and the question is if use this abstract union is not wisest
>
> becouse when someone says write char a =200 (when char on given platform is signed) and char b =200 then the question is if
> int c = a*b; shouldnt be in fact 40000
>
> should it or should not?

i mean then char is "signed char a =200;" and b is signed char b = 200
then the result should be probably -56*-56 but if a is "char a =200"
maybe the char shouldnt be either signed nor unsigned but 'abstract' and the result should be 40000 (maybe, i dont saying definitely)

Re: signed/unsigned - what will fail

<ubj09u$3ckl4$1@dont-email.me>

  copy mid

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

  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: Wed, 16 Aug 2023 19:16:46 +0200
Organization: A noiseless patient Spider
Lines: 76
Message-ID: <ubj09u$3ckl4$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> <HI4DM.141794$ftCb.112835@fx34.iad>
<ubilva$3as8c$1@dont-email.me> <%f5DM.670467$AsA.656909@fx18.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 17:16:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3485f3e07f3a2d2d489bd6daea567352";
logging-data="3560100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198BB5tDiRms/UOrpy/+omtb3MczoeOba4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:hqj7eoQaLzeQ8BZ/y+KSLgBSlXI=
Content-Language: en-GB
In-Reply-To: <%f5DM.670467$AsA.656909@fx18.iad>
 by: David Brown - Wed, 16 Aug 2023 17:16 UTC

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. The C standards require the macros to return the argument
unchanged except when the character can be made upper-case or
lower-case. Maybe these macros were from pre-C90 C, but they are pretty
useless as they stand. (C99 says they are functions, not macros, but
maybe that too has changed. The functions take an "int" argument, so
there is no attempt at arithmetic on (promoted) chars.)

>
> Unixware 2.01:
>
> #define isascii(c) (!((c) & ~0177))
> #define toascii(c) ((c) & 0177)
>
> #if defined(_XOPEN_SOURCE) || (__STDC__ == 0 \
> && !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE))
> #define _toupper(c) ((__ctype + 258)[c])
> #define _tolower(c) ((__ctype + 258)[c])
>
>>

Re: signed/unsigned - what will fail

<ubj0i9$3ckl4$2@dont-email.me>

  copy mid

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

  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: Wed, 16 Aug 2023 19:21:12 +0200
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <ubj0i9$3ckl4$2@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>
<9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 16 Aug 2023 17:21:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3485f3e07f3a2d2d489bd6daea567352";
logging-data="3560100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18skAxREpgH6mZy8NHivr+PSG7d1P1V/3c="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:FvvCbiqWkXnBbxOkrdxw95b7/No=
Content-Language: en-GB
In-Reply-To: <9d8b343f-c61b-4bc6-b73e-a2df1ece7a63n@googlegroups.com>
 by: David Brown - Wed, 16 Aug 2023 17:21 UTC

On 16/08/2023 16:35, Malcolm McLean wrote:
> On Wednesday, 16 August 2023 at 14:31:51 UTC+1, 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?
>>
>> 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);
>
> to convert from character to digit. But people like efficiency.
>

It would still not be arithmetic on chars.

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.

Re: signed/unsigned - what will fail

<ubj0pj$3cjsl$4@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.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 18:25:07 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <ubj0pj$3cjsl$4@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 16 Aug 2023 17:25:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="17f8aedb09110eed4ec1c7adfd187d70";
logging-data="3559317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+6bBg5HgcMDsHe0KqbQBAaU+hyG9QIBss="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.14.0
Cancel-Lock: sha1:jjQNNQVh9ILbbLPjiNqCZwgG7iY=
In-Reply-To: <ubij3o$3afvd$1@dont-email.me>
 by: Bart - Wed, 16 Aug 2023 17:25 UTC

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'

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

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

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

* 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.

Re: signed/unsigned - what will fail

<a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:198f:b0:405:5657:2510 with SMTP id u15-20020a05622a198f00b0040556572510mr26989qtc.0.1692207020814;
Wed, 16 Aug 2023 10:30:20 -0700 (PDT)
X-Received: by 2002:a17:902:cec1:b0:1b8:7f21:6d3 with SMTP id
d1-20020a170902cec100b001b87f2106d3mr1105267plg.6.1692207020293; Wed, 16 Aug
2023 10:30:20 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.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 10:30:19 -0700 (PDT)
In-Reply-To: <ubj0i9$3ckl4$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.144; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.144
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 17:30:20 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1955
 by: fir - Wed, 16 Aug 2023 17:30 UTC

ś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)

Re: signed/unsigned - what will fail

<fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ad4:5502:0:b0:649:74d0:c0ba with SMTP id pz2-20020ad45502000000b0064974d0c0bamr4058qvb.2.1692207199327;
Wed, 16 Aug 2023 10:33:19 -0700 (PDT)
X-Received: by 2002:a17:90a:e554:b0:269:2227:b290 with SMTP id
ei20-20020a17090ae55400b002692227b290mr488198pjb.7.1692207198802; Wed, 16 Aug
2023 10:33:18 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.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 10:33:18 -0700 (PDT)
In-Reply-To: <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=5.172.255.144; posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 5.172.255.144
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <fc09bb15-da9d-4d37-a419-362d33710a87n@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 17:33:19 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2311
 by: fir - Wed, 16 Aug 2023 17:33 UTC

ś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

Re: signed/unsigned - what will fail

<j%7DM.428704$U3w1.122961@fx09.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: signed/unsigned - what will fail
Newsgroups: comp.lang.c
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>
Lines: 65
Message-ID: <j%7DM.428704$U3w1.122961@fx09.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 16 Aug 2023 17:50:07 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 16 Aug 2023 17:50:07 GMT
X-Received-Bytes: 4010
 by: Scott Lurndal - Wed, 16 Aug 2023 17:50 UTC

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.

> The C standards require the macros to return the argument

The above header file predated the standard by a number of years.

Re: signed/unsigned - what will fail

<5c329846-44fb-4875-8a0a-cbfe3b5c40bcn@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:2510:b0:40f:c562:daa6 with SMTP id cm16-20020a05622a251000b0040fc562daa6mr7995qtb.3.1692215566443;
Wed, 16 Aug 2023 12:52:46 -0700 (PDT)
X-Received: by 2002:a63:3644:0:b0:566:128:80aa with SMTP id
d65-20020a633644000000b00566012880aamr486678pga.7.1692215566132; Wed, 16 Aug
2023 12:52:46 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!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 12:52:45 -0700 (PDT)
In-Reply-To: <a5e01b33-26de-4bea-bd7b-c02bf3e5012dn@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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5c329846-44fb-4875-8a0a-cbfe3b5c40bcn@googlegroups.com>
Subject: Re: signed/unsigned - what will fail
From: profesor...@gmail.com (fir)
Injection-Date: Wed, 16 Aug 2023 19:52:46 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: fir - Wed, 16 Aug 2023 19:52 UTC

ś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

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor