From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by sourceware.org (Postfix) with ESMTPS id DCA733940CE5 for ; Fri, 2 Oct 2020 19:33:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DCA733940CE5 Received: by mail-wr1-x441.google.com with SMTP id t10so2997420wrv.1 for ; Fri, 02 Oct 2020 12:33:05 -0700 (PDT) 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=CMINd+sBq25fYhka+s7H3s1lxbK8CIdRgBNffWgX4FXDCotORAVe+GNTgFx4AufDfD 3SwsrEukFSpdrJDb20ClZncp03DXJERt/IbK2NSmUKkSI6w6FCuflJgLnxOGPTvErcLz 7mLCJt1PW0qnCtwvOnJEVKlp6att+sbNn4tNUoGx0IlaECH1MG+1sDvIAYjT16/rwhBZ vniiYtVP+amywajLPExcvCO8Fo0PdOelHjRUBeRN1LI0pdGOOcY2TZzzCVBu3jloZXXj H0ExSDPzD8MHskpkdwCZnbcWd7pJrmetqLMKK8BbQOxPXZLmdPOu8gDplyN/IrAaHxXd gqyA== X-Gm-Message-State: AOAM532jVb4KAq4gdyYSOz9ihe6iV961IioKgemXC33eYzQckiR9yL55 MdIXrodeLKKnoN3t4/Vu7YM= X-Google-Smtp-Source: ABdhPJzRdcP1C/U7X5NIW2C1119M1D7zE/y6h08iotHPSHhQpQ1W5+CttUm/Yi+8VPj5/l7OKmZakQ== 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 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Oct 2020 19:33:07 -0000 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