From 93433f4023eae16aacad6cab2c0a0332c6f81955 Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 23 Mar 2001 20:19:22 +0000 Subject: [PATCH] Add section about cost of accessing params in a variadic function git-svn-id: svn://svn.cc65.org/cc65/trunk@657 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- doc/coding.sgml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/coding.sgml b/doc/coding.sgml index 072d76448..a24c8ba65 100644 --- a/doc/coding.sgml +++ b/doc/coding.sgml @@ -368,5 +368,22 @@ or instead will give shorter and faster code. +Access to parameters in variadic functions is expensive

+ +Since cc65 has the "wrong" calling order, the location of the fixed parameters +in a variadic function (a function with a variable parameter list) depends on +the number and size of variable arguments passed. Since this number and size +is unknown at compiler time, the compiler will generate code to calculate the +location on the stack when needed. + +Because of this additional code, accessing the fixed parameters in a variadic +function is much more expensive than access to parameters in a "normal" +function. Unfortunately, this additional code is also invisible to the +programmer, so it is easy to forget. + +As a rule of thumb, if you access such a parameter more than once, you should +think about copying it into a normal variable and using this variable instead. + + -- 2.39.5