From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 21C993858405 for ; Sun, 8 May 2022 17:29:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 21C993858405 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id CAB341E143; Sun, 8 May 2022 13:29:50 -0400 (EDT) Message-ID: <89fec0c3-8259-4951-5478-2afe6e0f1643@simark.ca> Date: Sun, 8 May 2022 13:29:50 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: Re: sizeof Content-Language: en-US To: Russell Shaw , GDB mailing list References: From: Simon Marchi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 May 2022 17:29:52 -0000 On 2022-05-08 11:22, Russell Shaw wrote: > When inspecting a C++ file, i get: > > (gdb) p sizeof(int()) > $82 = 1 > > (gdb) p sizeof(int) > $83 = 4 > > Not right ? > > Package: gdb > Version: 11.2-1 > on debian The compiler seems to agree with GDB: $ cat test.cpp #include int main() { printf("%zu\n", sizeof(int)); printf("%zu\n", sizeof(int())); } $ g++ test.cpp test.cpp: In function ‘int main()’: test.cpp:6:19: warning: invalid application of ‘sizeof’ to a function type [-Wpointer-arith] 6 | printf("%zu\n", sizeof(int())); | ^~~~~~~~~~~~~ $ ./a.out 4 1 I don't really know what sizeof(int()) means anyway. clang just rejects it: $ clang++ test.cpp test.cpp:6:19: error: invalid application of 'sizeof' to a function type printf("%zu\n", sizeof(int())); ^ ~~~~~~~ Simon