Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1554873pxk; Fri, 2 Oct 2020 12:34:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqIZSo7abYkQ7iYUoVqPVa+XkinD3S6ZwI02TSq4CACJ/uyMdD+y7SZCGMGA9+wz3srBRb X-Received: by 2002:a50:ee15:: with SMTP id g21mr4197733eds.47.1601667279407; Fri, 02 Oct 2020 12:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601667279; cv=none; d=google.com; s=arc-20160816; b=TaNFQE7cYB6EGx3OgDS7lSSF/b8vERLPCNW7x8eDlWf5C5cw3tt1jzwNaZsXcCuCZp VjSbSTbttr8M4TFMnapL8O+zE4ZV96o8NwdA3TfIjjjRfP2ioTyRVT4WSc72E0Q5dQMa i2CLW3pzxH1ogasBr38YpRN4mUGczHaCDrimNdKiWPohDj27Lxku4/nSpD1ouaAYovBs wAPbe3ohUFeBwGZE/FtBEmKg611Dn8Dlj4jCVBIQLPVAcS9i90zAWGMYUC4n6xWbqzFI 0+8K5IEqkEGP3tcXaDXic8dhGIFpsJGeOsthb2N5WX9e3UyKxYn/poe71h0S57Wh5Jmc zcgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VBFPk/Qft386bd0Dt7tJ3BwvEnIwt2MzSPH7alB/dmY=; b=h1hfRqqvUG5wERCkxfH165GYwyTrb7eXLo7tHN5xEFNO6dT/zGWu+zZqUMVNGUHeAP TX+2zeV5RGhzrH0uyW6SqXzo9LzL3+JxiYGuJX6G2Fbj+yMIbFRZk8CAuDhnsIfKSp2S 0MsyIQyHo4nNKZOr1eBXg3VW/alSaM3GWCnPV0uniEDG8FjyAQymnWUfn43FgBItziMy taKxoyRZ1XFdAHy7oLP/zUJ6ZSkPUpYHfxAlsFzOqxgwbTZAEV+3DkEiOV4ZmMkOi2Je To5usId7yXY7m30FFYv6+4rZtJfSmewjFx4Gwkn4amR2YBBedQYLmuMiMIIhTjt9hZJC 6ODQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G6Be0hEZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d2si2026516ejm.716.2020.10.02.12.34.17; Fri, 02 Oct 2020 12:34:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G6Be0hEZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388400AbgJBTdH (ORCPT + 99 others); Fri, 2 Oct 2020 15:33:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726224AbgJBTdG (ORCPT ); Fri, 2 Oct 2020 15:33:06 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D3C0C0613D0; Fri, 2 Oct 2020 12:33:06 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id c18so2961881wrm.9; Fri, 02 Oct 2020 12:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VBFPk/Qft386bd0Dt7tJ3BwvEnIwt2MzSPH7alB/dmY=; b=G6Be0hEZMa/j53dZd+gRkp5jt+f/frkOI+EsxPbSpOKSDZFdqzdJ6F0cNW4/qKbVek Zqe4orvZkxbEFMvLq2rgzbRoNhwEGIp9QdyC6yKBvqUs5IiQjRodJ4Vjhvhdgs+Lp+c7 4dHdH8BGgSjWbSXOhROxgWpPelfysDLx7h78OyuTa2do1MFLzQm7OQY2yETa6Ejq8fDP tgim4J12oJ/7LiAvJWc4TKYnzioopPRwyQxhjaCrActlVCdOdUC3nzfpXMo1NqZDx07Q J4C/+1UWDmdd9nk3JHX5N4zyXwa6xYOm8WVuFLTgUBIn2o6IGo3jniqnDXqtTVas0/2p wnUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VBFPk/Qft386bd0Dt7tJ3BwvEnIwt2MzSPH7alB/dmY=; b=SCde0rFoBIbSXmTXZvSEikU75Vk5/wvEOPHAt8PJr4BQC8XgwGRN36PoaT7Q8011i6 xwlGSDWSVO1XHePftcEzQ3hy5Ie1dnR6+nYxheaqCzzffy3XullLUGdHoYSdvCOqK6Uw +1Hd+wZihTWpkP1n0LIQ+buYcqCpN7ApqVd88SW01q8WCo1J+pUqwl6OxfkKOmh24W5G dL6WZN8NAg44VXTkX9Tzgx5M2vbDDQsgCK6+n/VoZhr55ztlzyVMVWo/pSISfSWao4eY 8ux82zt30QUP8KpM1ORcYBTYPpxNEJwqxyi9m0Mmy1H1i+UBogULYw3Vr3R3OwR94Sde emfw== X-Gm-Message-State: AOAM532KVQrgDTIRVhxqGyeXvGcIIX0quUSvHj9Ldi6qF2b/F0u8Dr8r 4gVdURfaeWfu986qzZEA0i4= X-Received: by 2002:a5d:5602:: with SMTP id l2mr4976722wrv.410.1601667185003; Fri, 02 Oct 2020 12:33:05 -0700 (PDT) Received: from localhost.localdomain ([170.253.60.68]) by smtp.googlemail.com with ESMTPSA id e19sm3384230wme.2.2020.10.02.12.33.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 12:33:04 -0700 (PDT) From: Alejandro Colomar To: mtk.manpages@gmail.com Cc: Alejandro Colomar , linux-man@vger.kernel.org, gcc-patches@gcc.gnu.org, libc-alpha@sourceware.org, eggert@cs.ucla.edu, linux-kernel@vger.kernel.org, jwakely.gcc@gmail.com, David.Laight@ACULAB.COM Subject: [PATCH v5 1/2] system_data_types.7: Add 'void *' Date: Fri, 2 Oct 2020 21:28:15 +0200 Message-Id: <20201002192814.14113-2-colomar.6.4.3@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002151419.32053-1-colomar.6.4.3@gmail.com> References: <20201002151419.32053-1-colomar.6.4.3@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Alejandro Colomar system_data_types.7: void *: Add info about generic function parameters and return value Reported-by: Paul Eggert Reported-by: David Laight Signed-off-by: Alejandro Colomar system_data_types.7: void *: Add info about pointer artihmetic Reported-by: Paul Eggert Reported-by: David Laight Signed-off-by: Alejandro Colomar system_data_types.7: void *: Add Versions notes Compatibility between function pointers and void * hasn't always been so. Document when that was added to POSIX. Reported-by: Michael Kerrisk Signed-off-by: Alejandro Colomar system_data_types.7: void *: wfix Reported-by: Jonathan Wakely Reported-by: Paul Eggert Signed-off-by: Alejandro Colomar --- man7/system_data_types.7 | 76 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/man7/system_data_types.7 b/man7/system_data_types.7 index c82d3b388..7c1198802 100644 --- a/man7/system_data_types.7 +++ b/man7/system_data_types.7 @@ -679,7 +679,6 @@ See also the .I uintptr_t and .I void * -.\" TODO: Document void * types in this page. .RE .\"------------------------------------- lconv ------------------------/ @@ -1780,7 +1779,6 @@ See also the .I intptr_t and .I void * -.\" TODO: Document void * types in this page. .RE .\"------------------------------------- va_list ----------------------/ @@ -1814,6 +1812,80 @@ See also: .BR va_copy (3), .BR va_end (3) .RE +.\"------------------------------------- void * -----------------------/ +.TP +.I void * +.RS +According to the C language standard, +a pointer to any object type may be converted to a pointer to +.I void +and back. +POSIX further requires that any pointer, +including pointers to functions, +may be converted to a pointer to +.I void +and back. +.PP +Conversions from and to any other pointer type are done implicitly, +not requiring casts at all. +Note that this feature prevents any kind of type checking: +the programmer should be careful not to convert a +.I void * +value to a type incompatible to that of the underlying data, +because that would result in undefined behavior. +.PP +This type is useful in function parameters and return value +to allow passing values of any type. +The function will typically use some mechanism to know +the real type of the data being passed via a pointer to +.IR void . +.PP +A value of this type can't be dereferenced, +as it would give a value of type +.IR void , +which is not possible. +Likewise, pointer arithmetic is not possible with this type. +However, in GNU C, pointer arithmetic is allowed +as an extension to the standard; +this is done by treating the size of a +.I void +or of a function as 1. +A consequence of this is that +.I sizeof +is also allowed on +.I void +and on function types, and returns 1. +.PP +The conversion specifier for +.I void * +for the +.BR printf (3) +and the +.BR scanf (3) +families of functions is +.BR p . +.PP +Versions: +The POSIX requirement about compatibility between +.I void * +and function pointers was added in +POSIX.1-2008 Technical Corrigendum 1 (2013). +.PP +Conforming to: +C99 and later; POSIX.1-2001 and later. +.PP +See also: +.BR malloc (3), +.BR memcmp (3), +.BR memcpy (3), +.BR memset (3) +.PP +See also the +.I intptr_t +and +.I uintptr_t +types in this page. +.RE .\"--------------------------------------------------------------------/ .SH NOTES The structures described in this manual page shall contain, -- 2.28.0