From nobody Wed Dec 14 05:45:39 2022 X-Original-To: dev-commits-src-main@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 4NX48h0cBSz4kvDR; Wed, 14 Dec 2022 05:45:40 +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 4NX48h087jz3NSX; Wed, 14 Dec 2022 05:45:40 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996740; 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=+TZ+y2Tl1lAFW5czyigXJ4ELH9cYukKbpVJbs3VCbto=; b=P31Qi3HyzRIvkJQIa7eKQt58IKTiF7IjHXLZJ4T7k4VEsI8rxo/0zjCXpNVJ2D9yiesc1l F2Lj7mmHnoNJOPyfC8ksClXKdohmAa7iakn6Cr0GzI1p2dCcmFM1xTSBSA0WrntqA9XCXM pRQRZ+yMuV4Pml0dGI96QvmXfNiYjcsfu78EIq+NupYF0/GfStvIna2SmdKmAypOBJLNPF Yfppv2hp4R0mfws/e3pMUBDRSwa29HNKaoN+NPSKooB5ER9+FX09QOulH4ZWi9PdTWxzYC 6/UfiPmmImYY7NUVL3MWaaHRVduvbc8tkj8pJopdaswAgmcad2Mi4GdoJ/lWVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670996740; 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=+TZ+y2Tl1lAFW5czyigXJ4ELH9cYukKbpVJbs3VCbto=; b=nQm9+Y5URp5niHym6JjTmIZpJ7/BIZDl0u9P2Wxe62L4j1dld9RstP9bSEyPJCreLbPqqa AONyPyBvueIxA0jZ6KNzNGxggZaIUNqe7pgrqHcE/JAD+IKw/Jz8qEqMcw+vwHPbtYL6MR MBMjGZSaEpbG/N8cmpR6SqnOL4YqN/kThDxWZCQw91rocszwD0z/yO91uwm3bGVATnBnsw LTozY56wvBjx5LRWQa+t4fe1dGGgo9li2iUiJkRjGfuFUWIzmXf0AoOXdc40kJ+KakWm3p /j37yRwniOuKUQAtxSl3CpQbPH+xssCqoPuCSFdg0KE+opmQEAvdprP8+wqLkQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670996740; a=rsa-sha256; cv=none; b=gNq3fABLuQntlplhPb6+wj6G66Sl8WMT1A648bFKuo9nMAzi/oe20doj6udo16YhI15VSf HvvJ8Jh5aeaqWbEetuDB2122zrtccxEqtz1F+mtUVkycphh5qQ2FPiE4WRtVDh/z4lp+wp 10oAQ8hO/FQD50IykMaDqUZP0HCvtKxZuUDSU18sC3t+tAd05TTymVKE5ysNcEDbd37xrD jKzVIrQoe7Va0+8/jLWnwom8F4VfisZTqvLdU6in07mjxooJnwrPyAIv9lM5jTLmfa9CDD k+5F4DUmZixI3fxPt142hIGRyqtnO8bEvepVvBtJ69CMexb1FAdMfvrWGxr3ow== 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 4NX48g652SzjB7; Wed, 14 Dec 2022 05:45:39 +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 2BE5jdeG033990; Wed, 14 Dec 2022 05:45:39 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BE5jdcW033989; Wed, 14 Dec 2022 05:45:39 GMT (envelope-from git) Date: Wed, 14 Dec 2022 05:45:39 GMT Message-Id: <202212140545.2BE5jdcW033989@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 9e0d976d95fa - main - sizeof(7): miscellaneous edits List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: 9e0d976d95fa4468ac423bc872bda0e93fa4bc18 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=9e0d976d95fa4468ac423bc872bda0e93fa4bc18 commit 9e0d976d95fa4468ac423bc872bda0e93fa4bc18 Author: Konstantin Belousov AuthorDate: 2022-12-13 14:07:32 +0000 Commit: Konstantin Belousov CommitDate: 2022-12-14 05:44:04 +0000 sizeof(7): miscellaneous edits Suggested by: pstef Reviewed by: imp, pstef (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D37683 --- 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