From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id 1A1CD3858D37 for ; Mon, 23 Oct 2023 11:36:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1A1CD3858D37 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 1A1CD3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698060997; cv=none; b=i7Zmhra8w/1vJjYEKk9hTi03GzrztLMxxCHsbhl67GvOK4eY4HvUf3yonpXd7eLVIR/lLyujVFWtB6Zbmzy1asjrqvH+FS7Ug/qpYZMsb4Xxk2mFZ6P0MSqJmsrkEQKBBJ4yBT6+PxooOCU6Cw02lr91yFyM6DfHMjcdYUQR/aM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698060997; c=relaxed/simple; bh=wuIsChc9Zx2MPe2fAkJ2PPannbAHwvvPfTzp7a1XE18=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=LlGxXj38xSzSdzqV82gEz2pg9QxK0oZPCrFCP79zb6cVRpBq7zz2zRPM6IXYE4ezNxKehRZTd1EGm3TwGNW1RUR7qi0+OVgND+EbjocwKvvUM7FaVh/hJvMApRmdlQXGS+tJBvCGaqZUdcnfoNrYHJDciNpPxiNWa80WZ+7N2MQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-40891d38e3fso11496255e9.1 for ; Mon, 23 Oct 2023 04:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698060994; x=1698665794; darn=gcc.gnu.org; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=z+naY7tczpLmO8qysbMH1Tngo3uYCfrvnpadqvdFAGs=; b=U+woR8fKGLi5cV/3HNISWXwF9PsQCb6nQimOUn8GafkfDM03k0OUA3EavAnTEwjHyS Zf0CFjNwSssna90OWo7TQu8+/YrrGt04r4AbvEmuJbo+J5TtAi9LD9iZ+pASFBeCY+o1 Ru2R9hvz3q5DJMUZUnEdt/XcdeO9/3ENBqTaKebA1sulvUMAA8Yli0MtylS6pUQ0kB+3 5oEkVRUDDmgJII9hlffEuZSld5IcZV0Y95XLw4h1ZX1ItZt12kDfpXyWzcNknw0YcPuE K7ddxCSmfYsXjvmBLtKw5rccPGhqBTL0Yys7sb0L9HQT+Qq4ZylnG2/xtJIBm+FXrSxZ N0Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698060994; x=1698665794; h=content-transfer-encoding:subject:from:content-language:to :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=z+naY7tczpLmO8qysbMH1Tngo3uYCfrvnpadqvdFAGs=; b=HpPoWThqr6eISFFevvy3eDeOtkLO9Hp5ikRccUEaB6ffnI1jbf1SoxGnMI7xmCDh4h hOePaeLTPaIXeJeUk3Ydxp130Flm4bkuNvR6JlSCmhiVsrm4Fo1rAe66zCIMKxOwXbsB fIeiXSiLF1BX0l4BQjGlS3tLFVL/IEuanJivpBFNU0qu9DstDShP+f0tuPV3rjZYN4XI xzCI5w8XNfYLP8QMBwhwYRqaGRUptKSabm2NYPkPKkzEkFr6lBlaYgiKuam2Ii109WsY TVSfsdd4ZijMXsDZDNA3L3DWTYi5XeGECpc4+yrTTDjyiKbU/O15fEWBbojl2qMHm0Hy c7pA== X-Gm-Message-State: AOJu0Yyq3Muhxsc8cyIx4NR7gaWh/tx062rn713C9cSUjvx9+mHYssQH Z1zpXoOywfHTV/9PBGfTZS9kIbVazFg2Bw== X-Google-Smtp-Source: AGHT+IFKYBJQ9CTWE1QFSiXqNMdyUXg8tsgAQs767WS7oET59ze7p8Sv64pk+W37+y17RODjV20E+Q== X-Received: by 2002:a05:600c:4f0f:b0:405:3885:490a with SMTP id l15-20020a05600c4f0f00b004053885490amr6600457wmq.0.1698060994365; Mon, 23 Oct 2023 04:36:34 -0700 (PDT) Received: from [138.96.197.38] (mururoa.inria.fr. [138.96.197.38]) by smtp.gmail.com with ESMTPSA id i18-20020a05600c481200b00407b93d8085sm13784840wmo.27.2023.10.23.04.36.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Oct 2023 04:36:33 -0700 (PDT) Message-ID: <32b868eb-2569-471c-8f19-aac7fc362c42@gmail.com> Date: Mon, 23 Oct 2023 13:36:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: libstdc++ Content-Language: en-US, fr-FR From: =?UTF-8?Q?Th=C3=A9o_Papadopoulo?= Subject: operator<< and int8_t and uint8_t types.... Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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:     Hi, I suspect that this will probably receive an answer "this is the intended/normal/expected  behavior", but from what I saw on the internet this is a kind of gray area in the standard and I did not found any (even closed) report on bugzilla, so I thought of asking here. Currently, printing a int8_t of uint8_t number with operator<< basically prints it as a (u)char. I think this is very unfortunate and is somewhat deceptive to users which expect a "int" like behavior. #include #include namespace std {     std::ostream& operator<<(std::ostream& os,const int8_t v) {         return os << static_cast(v);     }     std::ostream& operator<<(std::ostream& os,const uint8_t v) {         return os << static_cast(v);     } } int main() {     std::int8_t a  = 65;     std::uint8_t b = 66;     char         c = 'c';     std::cerr << a << ' ' << b << ' ' << c << std::endl; } Without the operator<< overloads: this code prints: A B c whereas I think a programmer would expect to see: 65 66 c which is what is obtained with the overloads. There is an old and extended discussion on stack overflow on the subject, in which from some comment it seems that it is the promotion to int vs the conversion to char that plays a role here (and that gcc like many over compiler favors the char conversion over the int promotion, but I'm not so sure about the validity of this discussion). Certainly from the user's perspective, one would expect to see and integer value and not a char... and it does not look very difficult to do.     Thank you in advance,         Theo.