Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1383966pxk; Fri, 2 Oct 2020 08:17:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzKDIZ8+Q0okzT33bHCimAp5pqsGB7wJVHXXM024nSaqrDz6S4DK8VuOx2Z5wZz/KawieQj X-Received: by 2002:aa7:d68c:: with SMTP id d12mr2906725edr.274.1601651827137; Fri, 02 Oct 2020 08:17:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601651827; cv=none; d=google.com; s=arc-20160816; b=h3xvrc04vqFy/i83BC5VRIyT9ck5ZVR0/Ixp/ZT0ZVfvHT59QbXxbNhTi8EpWgS47z UZUNp8lMFicPFHXT/SRvRzXEwnzguPRyX6wL1W5Y7tOFKNq2gjlFsgM9VEuJQ4Vi5tF2 rvyv+MrmjoNylO6jEl1RfCkusdHPuENNaEBbZ+NTPvPfkn+po7W9+M0E+zlIA1vQaNgf BK6N3ywOl8fR1XaaZYLH+kSG8PSjObRJtNnVNKUILhuBYaozJS+Eb9wEQFXoFOF0CxZw DPDtuD+OmxTXmsTyFOlaSU5zNQiY0GkdJiqxN15vF2muKaxLaXb93HBf/jIRXI0iRT0I 3Gag== 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=1jz81GvCHHwbiMMhfLuqkJObGuZK1aqG9396huA5nlY=; b=yzygJOvsD3JgwYDnIF8MBFx9QqPSXRYuZ/jaGjFwsztL4LYWA8sSG+tHH8QMRzTe3w Jd92BEmq5/arRWHY0rKsrWAR3AMGv7ia5dfkKZXQo7iMQff/E5kOxZGqIPi/BS9KeSci 4Kfg0HqaZmAA9xr3F0VQstUj+og4cLSG3521Tf1A6tMwSQuyLYj5iJHQuOQSRE2nUfrn plsGKVsNxD1Z25moh2PGJQGDsgx2dd03UH/I2EtjEQ8tMICK7Ey7PORDPkOQrXNKThTO UZZl+/YxuVax5qKpwQ1EFZolWGdIum7IIt/KVKogAxSWdudMCajeqz7a3RPO6s3Z6kFt 2hTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aM9gJLWF; 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 y7si299323edw.23.2020.10.02.08.16.44; Fri, 02 Oct 2020 08:17:07 -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=aM9gJLWF; 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 S2388321AbgJBPOy (ORCPT + 99 others); Fri, 2 Oct 2020 11:14:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388312AbgJBPOv (ORCPT ); Fri, 2 Oct 2020 11:14:51 -0400 Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34DE2C0613E2; Fri, 2 Oct 2020 08:14:51 -0700 (PDT) Received: by mail-wr1-x443.google.com with SMTP id x14so2204647wrl.12; Fri, 02 Oct 2020 08:14:51 -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=1jz81GvCHHwbiMMhfLuqkJObGuZK1aqG9396huA5nlY=; b=aM9gJLWFR/jkKEnckYry+dLRsq6iQbYyLEw2nIxph+XxJ9UXZHApgQjgoOO3AveCZJ ypeZZICjCts5a4XascoYFWywHSx80cJN/BoILzFPNZOMk2wDP/CgG9ZDb27rRP/f/J/a XSRmRLV9W5uju2YFk4zZgx3Say50NCIpe+pV5weUM8tRg7b9WrJmNMuW9CRZhgnFgkyz 3CamN78mLh0rMEOknLxeUXqzI2g5CKfsDWFxoIdpgtmHLHNLrINtnQlwLHnwmlueanbv sk9wmPvFY4JQMv3KloClnEbte763QU+UYUTEwfymENnGRG1ybKv6hLir1fUhFTxJMvqw +fCA== 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=1jz81GvCHHwbiMMhfLuqkJObGuZK1aqG9396huA5nlY=; b=KGkvbiBElVLQYu94PnDK9EbvqPnHBjDlelU439ZwXg4q6Ug+WG/tx3MCqRRA+wn+Yc GWQOM3/glgFTqdyPZD/wBu+0Juqm6nYu0Kn1SOOPIzjfndgxMD2MvXp1ZUpKNsSDgkf8 0BjJkU95Be0uLld7/xgwT/2H0dW38fv/OMQV/+OGU9klfOCH8o+bEyDmHlmEqklAHOVv BGCkeI6PvckZ5mzUYCd2QtWHW+/mhYc+WuJAV4sLLFrYSvgAlMaS7stEkh60CqT3qPqm XCqx3tYWxeSM9oDfMJohmRM8a/jZPYVLD186JKmiFndCEBEogX4fWAqY04jDVb4J9Yi3 E+0A== X-Gm-Message-State: AOAM532HudknhnumPZMNvr8Bqt6paPdtttLe1vteBkU9Twbwtmj38R3M N2a/kkh6Qsp7L878peJiJKU= X-Received: by 2002:adf:e481:: with SMTP id i1mr3621038wrm.391.1601651689820; Fri, 02 Oct 2020 08:14:49 -0700 (PDT) Received: from localhost.localdomain ([170.253.60.68]) by smtp.googlemail.com with ESMTPSA id u127sm2312237wmu.48.2020.10.02.08.14.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 08:14:49 -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, linux-kernel@vger.kernel.org, eggert@cs.ucla.edu, jwakely.gcc@gmail.com, David.Laight@ACULAB.COM Subject: [PATCH v4 1/2] system_data_types.7: Add 'void *' Date: Fri, 2 Oct 2020 17:14:19 +0200 Message-Id: <20201002151419.32053-2-colomar.6.4.3@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201002121645.23646-1-colomar.6.4.3@gmail.com> References: <20201002121645.23646-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 --- man7/system_data_types.7 | 80 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/man7/system_data_types.7 b/man7/system_data_types.7 index c82d3b388..277e05b12 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,84 @@ 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 cast 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 usually use some mechanism to know +of which type the underlying data passed to the function really is. +.PP +A value of this type can't be dereferenced, +as it would give a value of type +.I void +which is not possible. +Likewise, pointer arithmetic is not possible with this type. +However, in GNU C, poitner 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 ; +resulting commonly in +.B %p +for printing +.I void * +values. +.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