From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24211 invoked from network); 23 Jun 2021 16:01:55 -0000 Received: from minnie.tuhs.org (45.79.103.53) by inbox.vuxu.org with ESMTPUTF8; 23 Jun 2021 16:01:55 -0000 Received: by minnie.tuhs.org (Postfix, from userid 112) id 0F7D79CB5F; Thu, 24 Jun 2021 02:01:52 +1000 (AEST) Received: from minnie.tuhs.org (localhost [127.0.0.1]) by minnie.tuhs.org (Postfix) with ESMTP id 1ABC39C9DE; Thu, 24 Jun 2021 02:01:12 +1000 (AEST) Authentication-Results: minnie.tuhs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=papnet.eu header.i=@papnet.eu header.b="sACi57c9"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="V85M/npA"; dkim-atps=neutral Received: by minnie.tuhs.org (Postfix, from userid 112) id 797A59C9DE; Thu, 24 Jun 2021 02:01:09 +1000 (AEST) Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by minnie.tuhs.org (Postfix) with ESMTPS id CAA679C9AF for ; Thu, 24 Jun 2021 02:01:06 +1000 (AEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id C2485AB3 for ; Wed, 23 Jun 2021 12:01:05 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Wed, 23 Jun 2021 12:01:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=papnet.eu; h= date:from:to:subject:message-id:mime-version:content-type; s= fm2; bh=b3Dh6bNX0XCZDDUJqyralSe+MgZrzoqJqYTymx0QShA=; b=sACi57c9 ZQvlFeEoxFv8YcFqfjJSfen6d7lOguEfXfARM6NbcghshTit5uaMisNhd8jXYcz4 GuI1XkP9D9mYqbcqiuqynCL9bY8HhSlCzl0qLJ6OBYQcK62mV8Cc+zQdi2a3pY97 hsTXsR7kJhzwL+IbxWGhkXWmPnuOP941fG4k8OQD3UZ62Vbr4MPbUH+5hTJVCa30 WWtiVVMeMfhNnrzlVr/dCRBBX/11IFoa0PaBH7n+OZ7mqurqTTx+ZHHGHbJAoKQr /KWMEikWwmC4EM8e8MJHrlfuSd24lR3t3i8E274hKaGnvpWL9h4VTHDg+jthN1AK Ju7Bau+Hqc9GEA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=b3Dh6bNX0XCZDDUJqyralSe+MgZrz oqJqYTymx0QShA=; b=V85M/npARzjg6XOttJE7pXWdHld0Vc7pawrOTeWGuKdAZ nFG65uQ3Q7Ab1vmnEw2FhGdzTNiFQu36MbBFx9utGdxREdcJZZxhucJLBUloqf7R EVxCcK/YCicxcpYsBs0CaaiudW+dxOYKUtnCfFCd/LwP8kQ0tlVQBXx8AuxF7/K+ iQgauzD+tJO7Ceyy3o3l9IaT8vhCvE6iq5lXLLHY5BzLfj9GXHJegGdQjL6NYuFt 5Rgz2e05mXlvCKkZSTE8BIQjkkPHsOpPefw6K2VXS0GVvZQppyEnwLRe/dw9EQoU 4dZ2CGzMUzZTa8mVNYCNKAJeHqtxTzJVxE6xvqUAA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrfeegfedgleekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkgggtugesthdtredttd dtvdenucfhrhhomheptehnghgvlhhoucfrrghpvghnhhhofhhfuceorggrphesphgrphhn vghtrdgvuheqnecuggftrfgrthhtvghrnhepleejhfdujeegfeejgfeljeetvedujeefle ejfeevhfevfefhudekjeejtdehuefhnecuvehluhhsthgvrhfuihiivgeptdenucfrrghr rghmpehmrghilhhfrhhomheprggrphesphgrphhnvghtrdgvuh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 23 Jun 2021 12:01:04 -0400 (EDT) Date: Wed, 23 Jun 2021 18:01:02 +0200 From: Angelo Papenhoff To: tuhs@minnie.tuhs.org Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Subject: [TUHS] "The programmer must have been carried away ... X-BeenThere: tuhs@minnie.tuhs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: The Unix Heritage Society mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tuhs-bounces@minnie.tuhs.org Sender: "TUHS" ... when he declared all the parameters for this procedure" I'm sure some of you remember this quote expressing John Lions' puzzlement over the declaration of printf in the UNIX kernel: printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9,xa,xb,xc) Note that parameters x2 and following are never referenced by name in the function body, only by pointer arithmetic from &x1. The historical reason for this long list of parameters is probably not well known, so I want to explain it and hope that you will find it as enjoyable as I did when I came across it some time ago while studying leftover files of B. To call a function in B, there's a little dance you have to do: first push the function address onto the stack, remember the stack pointer, push all the arguments, then restore the stack pointer and do the actual call. In diagrams, this is what happens to the B stack: push func addr: +------------+ | | <- sp +------------+ | func addr | +------------+ mark (n2): +------------+ | | <- sp +------------+ | | <- old sp (saved on native stack) +------------+ | func addr | +------------+ push arguments: +------------+ | | <- sp +------------+ | arg n | +------------+ | ... | +------------+ | arg 0 | +------------+ | | <- old sp (saved on native stack) +------------+ | func addr | +------------+ call (n3): pop old sp from stack jump to func addr on stack set ret addr and old fp +------------+ | arg n | +------------+ | ... | +------------+ | arg 0 | +------------+ | ret addr | +------------+ | old fp | <- sp, fp +------------+ The callee then sets sp, so has to know how many args and automatics! +------------+ | | <- sp +------------+ | auto n | +------------+ | ... | +------------+ | auto 0 | +------------+ | arg n | +------------+ | ... | +------------+ | arg 0 | +------------+ | ret addr | +------------+ | old fp | <- fp +------------+ So because the arguments to a functions were grouped together with the automatics and not below the ret addr and saved fp, there has to be space on the stack lest they clash. This of course means that this printf in B would probably break if called with more arguments than it expects. So there you have it. Just a line of B code that wasn't updated to C. Cheers, aap