From nobody Tue Dec 20 00:55:42 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NbdRL6kGWz1GLYc; Tue, 20 Dec 2022 00:55:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NbdRL5mMFz3pQp; Tue, 20 Dec 2022 00:55:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671497742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=++vCfqkDmRZ9vJBs3Tm9t1WK1p6PCNukxVu7AaklZvo=; b=Znt40tHdT06ZLTqIq5uYbq+95bnypxG5M3yIUzsB03v0KZQWG1lAzNlCqCI2Phc31UTmls Wve5LMdYEEzoQltr0H2QbLtojlDV6fd0Qg0Sgta8Q05q5eR8Ht8NJMJRF7BVlOFfDlxu5j OUxWnl/DEvORZuH6CbMdnvcKAbM1qwGlhgGxc/G0eTYjqnwGxFzWVIeUld7l1tZTGB0VMy SkS/O3IHa6u0Ch0Jb+B5PElxPCKgC7jjHSqctYdetPfKjliM738f+CRnGIDeWZP9KdNnu+ Px5S4XPMRZFqREf1MEkd2n3qnHMMeZV4iRkTfLB+tMgqBeecL5fM1dMwHRSGgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1671497742; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=++vCfqkDmRZ9vJBs3Tm9t1WK1p6PCNukxVu7AaklZvo=; b=Tt/71K3k1z1dwp2P7bgTcmFG33XnZ+M6p7a/xgWt77h5ZUcie1L8dcL3xWG9wuNJqTeRaO z9EmWoRK8q8FcEQaIE/Czy+cnYlqjOCg/vKJ1YN0RbpYBaOf8+OVK1Ny0wQCs/hkM3N17D baWv5MX9WisyimAxmEpGFQQFCK/CUcaYXlc3lmCydmGEFXWSw1c2u+Js8PteGvMUH0UQF7 b9Ht8ocKvlLsll1/5lhYyHFs+V8I3XktUYu/GTYcPydEjsTr4fQIbLGS5dmcc9Ah4LNWbz YUGYIocdRpTuKzMdq0k/q89OLxrt+ww/Kx+3QZvEqUHenPSsNHHcH8KyjWA3sA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1671497742; a=rsa-sha256; cv=none; b=aUMhYeGmsRstXj2piYZmgfNrYfmhY5NpX055vkXhYKvw0G4yKGVmwROQIEzCezYBU/oSeP IkMbrTo4xNzbTB1VLyTbf+x7bd6HNKJ7sGDVId3k70wdptMwyo+szNnlUKVJW7lr1f7Beb /KwDXfOqbRCLnsyGYhJGbmOIEX+2lmN2cdgrP+9nUf17j0H39781113SQYZRxtrTagvql5 qbvdcdGr1U0pabv8jlCbPI6mY0YWkA01GRNWl2CbdZXnlHfVuUFaDiP/HkQ5fjXJqG96Hn rowPoUCMWlPyAqnVCAeqnBtYrXivrvSsthEPOmfTuhSpH5cMh/gFEGVXsxFA2A== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NbdRL4Y3xzGW4; Tue, 20 Dec 2022 00:55:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BK0tgYx086386; Tue, 20 Dec 2022 00:55:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BK0tgNs086385; Tue, 20 Dec 2022 00:55:42 GMT (envelope-from git) Date: Tue, 20 Dec 2022 00:55:42 GMT Message-Id: <202212200055.2BK0tgNs086385@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 384a885111ad - stable/13 - sizeof(7): miscellaneous edits List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 384a885111ada8b21f51542f48559c4cbce44f7b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=384a885111ada8b21f51542f48559c4cbce44f7b commit 384a885111ada8b21f51542f48559c4cbce44f7b Author: Konstantin Belousov AuthorDate: 2022-12-13 14:07:32 +0000 Commit: Konstantin Belousov CommitDate: 2022-12-20 00:53:47 +0000 sizeof(7): miscellaneous edits (cherry picked from commit 9e0d976d95fa4468ac423bc872bda0e93fa4bc18) --- share/man/man7/sizeof.7 | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/share/man/man7/sizeof.7 b/share/man/man7/sizeof.7 index 4abc08490d65..b3c3af1acb52 100644 --- a/share/man/man7/sizeof.7 +++ b/share/man/man7/sizeof.7 @@ -34,17 +34,38 @@ operator .br .Nm Vt expression .Sh DESCRIPTION -The size of primitive data types in C may differ +The +.Nm +operator yields the size of its operand. +The +.Nm +operator cannot be applied to incomplete types and expressions +with incomplete types (e.g. +.Vt void , +or forward-defined +.Vt struct foo ), +and function types. +.Pp +The size of primitive (non-derived) data types in C may differ across hardware platforms and implementations. +They are defined by corresponding Application Binary Interface (ABI) +specifications, see +.Xr arch 7 +for details about ABI used by +.Fx . It may be necessary or useful for a program to be able -to determine the storage size of a data type or object. +to determine the storage size of a data type or object +to account for the platform specifics. .Pp The unary .Nm operator yields the storage size of an expression or data type in -.Em char sized units . -As a result, 'sizeof(char)' is always guaranteed to be 1. +.Em char sized units +(C language bytes). +As a result, +.Ql sizeof(char) +is always guaranteed to be 1. (The number of bits per .Vt char is given by the @@ -72,8 +93,7 @@ on an ILP32 vs. an LP64 system: .Pp When applied to a simple variable or data type, .Nm -returns the storage size of the data type of the -object: +returns the storage size of the data type of the object: .Bl -column -offset indent \ ".Li sizeof(struct flex)" ".Sy Result (ILP32)" ".Sy Result (LP64)" .It Sy Object or type \ @@ -128,7 +148,7 @@ platforms, as they are based on character units. .Pp When applied to a struct or union, .Nm -returns the total number of units in the object, +returns the total number of bytes in the object, including any internal or trailing padding used to align the object in memory. This result may thus be larger than if the storage @@ -251,8 +271,10 @@ if ((buf = malloc(BUFSIZ)) == NULL) { .Ed .Pp In that case, the operator will return the storage -size of the pointer ('sizeof(char *)'), not the -allocated memory! +size of the pointer ( +.Ql sizeof(char *) +), not the +allocated memory. .Pp .Nm determines the