public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Olavi Esker <olavi.esker@gmail.com>
To: gcc@gcc.gnu.org
Subject: int8_t lives matter
Date: Fri, 22 Dec 2023 23:53:17 +0200	[thread overview]
Message-ID: <CALA5SxzgKFEGtjah4XqBApBe0jJKtfxf-c5BRi1QGGAn+9+FGQ@mail.gmail.com> (raw)

[-- 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

             reply	other threads:[~2023-12-22 21:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-22 21:53 Olavi Esker [this message]
2023-12-22 22:03 ` Andrew Pinski
2023-12-23 10:35   ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CALA5SxzgKFEGtjah4XqBApBe0jJKtfxf-c5BRi1QGGAn+9+FGQ@mail.gmail.com \
    --to=olavi.esker@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).