From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by sourceware.org (Postfix) with ESMTPS id BD5E93858C98 for ; Sat, 2 Dec 2023 11:50:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD5E93858C98 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org BD5E93858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2604:1380:4641:c500::1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701517841; cv=none; b=sKUiMCu46MfsPDcEN72HrCafmp9tJ+ObNVTBDBZcxepDDf5JsQB/MCgI1kYqjbLl8D+fdY/UjEC6cywW8tuFX+GyFY+rMrMn4N7DUYxYqLOCFd9Y3f7LNbjBs8jfwTCci9MoL3J28JdpsDmTif7BrHBoCiVb23ezWwJR0iV03aI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701517841; c=relaxed/simple; bh=kmP7jyEl0BMVDndOXH4SKt3IXXXVdi7RoOfxfFc5bfI=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=CUJQLjzV4nqLcK+El7Z9AvJu8alY12AvJFqhtVDYeo9IpvDDVyvkDx0Fkqi03VkrqFXFW5FHryi//xO6w1eDikAAduN5ZV/JePLxgpUylWfhTbaz3QaNiYV8Pe8PSyLTLdx4pJuAXiAxae+o1qyxpNG6fO/cp8oiK4JnMnoakSM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 4EE5B60B25; Sat, 2 Dec 2023 11:50:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3A6BFC433C8; Sat, 2 Dec 2023 11:50:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701517837; bh=kmP7jyEl0BMVDndOXH4SKt3IXXXVdi7RoOfxfFc5bfI=; h=Date:From:To:Subject:From; b=uYW7vMivMUcMUg+ks7lLWiwo3n7r6RkK4QO+n+P52dCJlJw5QiwDKLUlNVu2ZI/J4 aZ+yB0fdU81RDRDBtXjDASI+8OWIiG2hMPVJ0kHZJuuZvTDiBvN5687bDYRFzhq/5I UdD0gwJ3xLcxwh98COiN2pQ1qsv4d0GI3tR/yH48JE7rcWSK12/1bNrI16jxT/5ITT CP4eOWC1bS6tTvUFzoJQS37QMF27bTgvxLwUhXvPnJ8WEAo4GE1cS2Hti2lubuPzhx r4DPvUw1YP0e+IOLQ5zVYEphTF11snIBBLqyQOuqDXC6Z9/o/ndCJWNGdn/9VwivUo R5NfMJPJh+aAA== Date: Sat, 2 Dec 2023 12:50:28 +0100 From: Alejandro Colomar To: libc-help@sourceware.org, gcc-help@gcc.gnu.org Subject: restrictness of strtoi(3bsd) and strtol(3) Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="glngv/xt4MyREWVE" Content-Disposition: inline X-Spam-Status: No, score=-3.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --glngv/xt4MyREWVE Content-Type: text/plain; protected-headers=v1; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Date: Sat, 2 Dec 2023 12:50:28 +0100 From: Alejandro Colomar To: libc-help@sourceware.org, gcc-help@gcc.gnu.org Subject: restrictness of strtoi(3bsd) and strtol(3) Hi, I've been implementing my own copy of strto[iu](3bsd), to avoid the complexity of calling strtol(3) et al. In the process, I've noticed that all of these functions use restrict for their parameters. Why do these functions use restrict? While the second parameter is not used for accessing nptr memory (**endptr is not accessed), it can point to the same memory. Here is an example of how these functions can have pointers to the same memory in the two arguments. l =3D strtol(p, &p, 0); The use of restrict in the prototype of the function could result in compiler warnings, no? Currently, I don't see any warnings, but I suspect the compiler could complain, since the same memory is available to the function via two different arguments (albeit with a different number of references). The use of restrict in the definition of the function doesn't help the optimizer, since it already knows that the second parameter is out-only, so even if it weren't restrict, the only way to access memory is via the first parameter. Thanks, Alex --=20 --glngv/xt4MyREWVE Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE6jqH8KTroDDkXfJAnowa+77/2zIFAmVrGgQACgkQnowa+77/ 2zJ0tg//aQ1MkCGs1S8hYduvuKTwf/Hoxq4clfuvo/fw1EncxhiUGQvgt8HXIc8I Ib7eUc76Qe1RV2+JcoAWwChLa0NHioBR3eDcy0HzZfCusWmK91nSGoCD3N8qmQmZ /z853KaojtmIA4YjaS/Nt3VgJ4GtXFwPKXYfiuZK/294y8lo4WQQIBEbnh8sX7Tg Y/0exNM+ZMpHD7h6bCp2VcLNO8g68kIK26QhXOvPGYxeV7PScK6M78u0P3eXFgxk +NUGJ3G7JXlBvOX5WQF+YZr0zLnO7iLIvmKbg92VhaFgJbW2nlAinTojlPqCOlrN ZedX6d6drCTmvI36/z+nzZ6UzXnFhhz6OUNhiLI9ZX6gbVJvdaqs1HEn6F8Yfywo r1ZqO10J1ShCFBBTJaOLP2Kz8Wfd+SQEJ6ZwF48hRrbD4i11KU1SLlPoJZbtEvzV bN6scGcICYuwyqkMDrQoJvrhX/iKup67oDfTZ+lKRdoIPhTwPi/7UtwCRpZ59tFy 8jZHBdGO81cuoUMst7fLzW4O3yi/ROrgT6xqtMReXvKIXfFEBFKp8OlJkro4xTeC BQ7wC9/YauVtyaO5m2V3MnJRvnaBBQooqlmq7jlvS6vDupwE8Bt1ryZIG+5HWIhL sxcDi5TKKZhrelzelBOH/i9H539rT77p+6bjJv7KxhRaIjsObiU= =y7Kb -----END PGP SIGNATURE----- --glngv/xt4MyREWVE--