From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by sourceware.org (Postfix) with ESMTPS id 017423858C98 for ; Sat, 23 Dec 2023 10:31:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 017423858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 017423858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::629 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703327478; cv=none; b=wfcnQK1dfJKcA75q9SxPIrL4DnkrtFQJolYUxeFWF2xr7oWsJAMtxsLiXm/4x9uSPSMmcF2NrExnOGnY3Gtdu1jLXBVbl7SCoLtU82a8RUmOX1dnc3G/o0zHdAY5sDfpcI2E8DAToSLSARt4fx4DaWP3rawKWwNFIgcdIYtEmt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703327478; c=relaxed/simple; bh=/s02j9KWUDVBn2mab1UmorcPbF367wqv0pl5rMWnLEs=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=GN7kc8CIokzgaR0AB3Y18DmsEissNnPHqDm+/P5lpTuRQArEX/sPExZzJfEP0g8porQzHKZloaqvDvgQyUVM9X0oDTv6XKpgJKf3tGGLjceEmBCGf4lXf1NCA8gGu2oG+EdHmppWZxcNift3IUFBpATNyrEgSYUwDpsLJZLbkVw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a265d4f78bfso217907266b.0 for ; Sat, 23 Dec 2023 02:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1703327475; x=1703932275; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=PZjUFfuCBH4zlW8mKTVVi59qCBS6AsY85eD0wbY7aQ0=; b=JCk00JAa2UwZzNrs34R+NmW2/pqqlEOTDKlcD8il8u56VHS7kQkAORax6DeHC5yIkL cTPei721SnlT+Ama+WyO1OtqhQHHkqMIOnavwrPa1XHOKPHpHwTruxhLuZYH+4uUCcXr P0irLK0XnL/BO6i59udpBb4TY6UhTnsO5iK5Qz/hp5IOxTSnvDrLc+d9XFUOkSS/uNSw Tzc2ZHiSC2wyM1gFtRWC++SjC2o20O72F2tUUWgdpslJGdedlb8IJTZYU7GcQ419zjAo 3xs4IItRczZ2jCAyK3OXSvt4HyZKD6hdzAcA+hQM4adaqkLt/MKSVxyYzWIJ3k23pk4r R0Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703327475; x=1703932275; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=PZjUFfuCBH4zlW8mKTVVi59qCBS6AsY85eD0wbY7aQ0=; b=up96+zW9ol2LE75rFHC6XULJxvhvgIfc/3xSSW6U6zmiVi8RgJO4iXkwEkBJXdJCMc t5r0rFih7RdLkMcV1+DOJeOjUpicwlvdmY/JOJcgp7N/PVuvCupouLTksEfMnI7sLJql EuQxVmcIJ22pjVSlLIYrAPb0ZYHI6wPQ5TIBE2OqAiEvsSGsRz3WHb2BbEkh1LOLJpIl o686R/oO47iWTaKMV4M2tWtpccpW7ci2Vf+fStiV6wu0LWkysCcv+YpPpVC1iZsxbIUO LyktUU2oVojo9mRLFdE9zQKZ+iySNUp1e7CB5DZma4PKPmmoyHOOO364uuk0ueK5+mk3 o1gw== X-Gm-Message-State: AOJu0Yw9kB9pGmomOep43aQee1DTA/hbt/3X4KHyBZALFXcUqG2FaZTu cmvPOvwdy9fzYAe6nVhAz48mIKyATCWudL/y+CVKfeeN X-Google-Smtp-Source: AGHT+IH99mXy2EVl6qekDggTbCiPmoW3YhxPUjsqPRHfrOofEp1blaw1dpcBsGgGgvKDPtQJSY6mwixWDSJemcTzxXM= X-Received: by 2002:a17:907:7e8c:b0:a18:d66e:c62b with SMTP id qb12-20020a1709077e8c00b00a18d66ec62bmr2253135ejc.29.1703327475544; Sat, 23 Dec 2023 02:31:15 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Sat, 23 Dec 2023 10:31:03 +0000 Message-ID: Subject: Re: int8_t outputs char via To: Olavi Esker Cc: gcc-help Content-Type: multipart/alternative; boundary="0000000000001db715060d2ad558" X-Spam-Status: No, score=-0.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --0000000000001db715060d2ad558 Content-Type: text/plain; charset="UTF-8" On Sat, 23 Dec 2023, 00:15 Olavi Esker via Gcc-help, wrote: > Hello, > With int8_t prints out char according to ascii number. Similarly > it reads a single char, which cannot be static converted. The compiler > gives no warning whatsoever. But when is used with scanf %hhd and > printf %d it works perfectly. It's a bit misleading to say that printf %d works perfectly, when it does an implicit cast to int which behaves exactly the same as using char with %d. Is this really the intended > functioning? In Rust i8 In Rust isn't it a distinct integral type, not just a typedef for a character type? So not comparable. and C int8 works fine, too. > #include > #include > > 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". > > > It 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, or at least have a warning, because > functions fine for higher bitted integers. > > Thanks. > OE > --0000000000001db715060d2ad558--