public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* int8_t lives matter
@ 2023-12-22 21:53 Olavi Esker
  2023-12-22 22:03 ` Andrew Pinski
  0 siblings, 1 reply; 3+ messages in thread
From: Olavi Esker @ 2023-12-22 21:53 UTC (permalink / raw)
  To: gcc

[-- Attachment #1: Type: text/plain, Size: 1068 bytes --]

Hello,

#include <iostream>
#include <cstdint>

int main()
{
std::int8_t myInt{65};
myInt += 1;
std::cout << myInt;
}

Guess what this returns?
Character "B".

int main()
{
std::int8_t myInt{};
std::cin >> myInt;
std::cout << myInt;
}
This will also read a character, and
print the characters ascii value.
So if I give it 3, it read it as '3', and prints out 51.


The compiler gives no warning of this whatsoever with the flags:
                "-std=c++20",
                "-pedantic-errors",
                "-Wall",
                "-Wpedantic",
                "-Wshadow",
                "-Wcast-align",
                "-Wlogical-op",
                "-Wno-unused-parameter",
                "-Weffc++",
                "-Wextra",
                "-Wconversion",
                "-Wsign-conversion".


t does seem like a mistake to have `signed char` and `unsigned char`
display as characters rather than numbers, since `char` is a distinct type.
And so `char` could display as a character and the other two as integers.

Wish you can change this.

Thanks.
OE

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: int8_t lives matter
  2023-12-22 21:53 int8_t lives matter Olavi Esker
@ 2023-12-22 22:03 ` Andrew Pinski
  2023-12-23 10:35   ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Pinski @ 2023-12-22 22:03 UTC (permalink / raw)
  To: Olavi Esker; +Cc: gcc

On Fri, Dec 22, 2023 at 1:54 PM Olavi Esker via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hello,
>
> #include <iostream>
> #include <cstdint>
>
> int main()
> {
> std::int8_t myInt{65};
> myInt += 1;
> std::cout << myInt;
> }
>
> Guess what this returns?
> Character "B".
>
> int main()
> {
> std::int8_t myInt{};
> std::cin >> myInt;
> std::cout << myInt;
> }
> This will also read a character, and
> print the characters ascii value.
> So if I give it 3, it read it as '3', and prints out 51.
>
>
> The compiler gives no warning of this whatsoever with the flags:
>                 "-std=c++20",
>                 "-pedantic-errors",
>                 "-Wall",
>                 "-Wpedantic",
>                 "-Wshadow",
>                 "-Wcast-align",
>                 "-Wlogical-op",
>                 "-Wno-unused-parameter",
>                 "-Weffc++",
>                 "-Wextra",
>                 "-Wconversion",
>                 "-Wsign-conversion".
>
>
> t does seem like a mistake to have `signed char` and `unsigned char`
> display as characters rather than numbers, since `char` is a distinct type.
> And so `char` could display as a character and the other two as integers.
>
> Wish you can change this.

First this is the wrong email list, it should be sent to gcc-help@.
Second, your subject line can be read as being offensive to some folks
due to the use of the phrase "lives matter".
Third, this is what the C++ standard says it should be. And it might
be better to be brought up to a C++ forum rather than one about the
GCC implementation of the C++ standard.

Thanks,
Andrew Pinski

>
> Thanks.
> OE

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: int8_t lives matter
  2023-12-22 22:03 ` Andrew Pinski
@ 2023-12-23 10:35   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2023-12-23 10:35 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: Olavi Esker, gcc

[-- Attachment #1: Type: text/plain, Size: 1940 bytes --]

On Fri, 22 Dec 2023, 22:04 Andrew Pinski via Gcc, <gcc@gcc.gnu.org> wrote:

> On Fri, Dec 22, 2023 at 1:54 PM Olavi Esker via Gcc <gcc@gcc.gnu.org>
> wrote:
> >
> > Hello,
> >
> > #include <iostream>
> > #include <cstdint>
> >
> > int main()
> > {
> > std::int8_t myInt{65};
> > myInt += 1;
> > std::cout << myInt;
> > }
> >
> > Guess what this returns?
> > Character "B".
> >
> > int main()
> > {
> > std::int8_t myInt{};
> > std::cin >> myInt;
> > std::cout << myInt;
> > }
> > This will also read a character, and
> > print the characters ascii value.
> > So if I give it 3, it read it as '3', and prints out 51.
> >
> >
> > The compiler gives no warning of this whatsoever with the flags:
> >                 "-std=c++20",
> >                 "-pedantic-errors",
> >                 "-Wall",
> >                 "-Wpedantic",
> >                 "-Wshadow",
> >                 "-Wcast-align",
> >                 "-Wlogical-op",
> >                 "-Wno-unused-parameter",
> >                 "-Weffc++",
> >                 "-Wextra",
> >                 "-Wconversion",
> >                 "-Wsign-conversion".
> >
> >
> > t does seem like a mistake to have `signed char` and `unsigned char`
> > display as characters rather than numbers, since `char` is a distinct
> type.
> > And so `char` could display as a character and the other two as integers.
> >
> > Wish you can change this.
>
> First this is the wrong email list, it should be sent to gcc-help@.
> Second, your subject line can be read as being offensive to some folks
> due to the use of the phrase "lives matter".
>

(The thread has moved to gcc-help now)


Third, this is what the C++ standard says it should be. And it might
> be better to be brought up to a C++ forum rather than one about the
> GCC implementation of the C++ standard.
>
> Thanks,
> Andrew Pinski
>
> >
> > Thanks.
> > OE
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-23 10:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-22 21:53 int8_t lives matter Olavi Esker
2023-12-22 22:03 ` Andrew Pinski
2023-12-23 10:35   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).