From patchwork Fri Oct 2 12:16:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 40634 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41D8D398D032; Fri, 2 Oct 2020 12:17:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 41D8D398D032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601641032; bh=1jz81GvCHHwbiMMhfLuqkJObGuZK1aqG9396huA5nlY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=eHh+c7jcFdkBsZOE2YI1Dl9+jdHzA11wc1WQyIhpFYXnkZSDqTGKEUCfGP4p0pDKo Qi+kwhxggGFTXGveT5FkJa+4Tn9clzInOh3p4aHlHCUXyYmN+xE9s1ClHJjKYbmAcK qBwEpUStpcqRvDR4ONymihdT20awZQu9rAHr/JwY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by sourceware.org (Postfix) with ESMTPS id 6E6DC386F440 for ; Fri, 2 Oct 2020 12:17:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6E6DC386F440 Received: by mail-wm1-x343.google.com with SMTP id k18so1531948wmj.5 for ; Fri, 02 Oct 2020 05:17:09 -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=1jz81GvCHHwbiMMhfLuqkJObGuZK1aqG9396huA5nlY=; b=ie33dbY7MkxICGR7hENtg/Xg/EMW3rHs8+QJqs/0ja+SSw1CLJxflGYJBRArg820Va PaCD1oQQtP4SG4rYBTBQ96I705yXgyeVsNy+tqdu9qfaggXyxSRG31o+irOkIMyfpm2z w1nJdIjKcfun733fLksDK6D5cmpIClRThuusBxlhRdVPr+8n4k0EXcGrxE8+/tPoGWmD ed6h6Km5YemAepNgYEKlrNS6wB8LzNwd2/PHjWguUaIxj3saZDwaReWqoL9290A6rIZn 7Dp5WcX6mKh6k5ggkUMNGO9w9A/nQk59+30dFP+V9yg5Y+Wp9Z+VVk5MYiZHulVO6wnv +3fA== X-Gm-Message-State: AOAM5327Cd08THtfsxymbExnqD8jtOfEmSUkVC1/J2YHm55qKING4vaT agcg+U7Axu3uWWeondNPS5c= X-Google-Smtp-Source: ABdhPJzmQr4Fij7t6PVUNzclmBRRE7rmYPPR5h7Fstz4X47910ieGnMxoD3+GQD8ZpvxM5mZK+yTSg== X-Received: by 2002:a7b:cb44:: with SMTP id v4mr2596003wmj.101.1601641028474; Fri, 02 Oct 2020 05:17:08 -0700 (PDT) Received: from localhost.localdomain ([170.253.60.68]) by smtp.googlemail.com with ESMTPSA id h17sm1710569wro.27.2020.10.02.05.17.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 05:17:07 -0700 (PDT) To: mtk.manpages@gmail.com Subject: [PATCH 1/2] system_data_types.7: Add 'void *' Date: Fri, 2 Oct 2020 14:16:45 +0200 Message-Id: <20201002121645.23646-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 X-Spam-Status: No, score=-9.3 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: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alejandro Colomar via Libc-alpha From: Alejandro Colomar Reply-To: Alejandro Colomar Cc: linux-man@vger.kernel.org, jwakely.gcc@gmail.com, libc-alpha@sourceware.org, Alejandro Colomar , linux-kernel@vger.kernel.org, David.Laight@ACULAB.COM, gcc-patches@gcc.gnu.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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,