From: George O. <g.o...@br...> - 2012-07-13 14:32:34
|
Hi all, I'm attaching a simplified version of a scenario where we have a static function foo() which takes a few arguments. We never need its address and never use it in a FP. In this scenario, foo calls something which calls something else and so on. What I'm trying to achive is inline foo() in order to reduce some stack usage. First attempt to make it static inline, like s_foo in the attached example. The compiler 'may' emit an out-of-line version and in this instance SDCC does. So far so good but I want to do this without increasing my code size even further by having a separate implementation. Q1: As far as I can tell, there is no way of stopping SDCC from providing this implementation. Am I missing a trick? Next attempt is, change s_foo() to inline but not static. This compiles, links, inlines s_foo() and does not implement it separately. Q2: inline void s_foo() has external linkage but I'm not providing an implementation elsewhere. Are we OK standards-wise in this case? I've read conflicting opinions on this: This says that, according to the standard, it -must- be implemented in another translation unit: http://sourceforge.net/projects/sdcc/forums/forum/1864/topic/4515873 This says that the standard's vague: http://www.greenend.org.uk/rjk/tech/inline.html Is SDCC doing the right thing here by not complaining? Does this code risk build failures in future SDCC versions? Q3: Next step is, provide a definition for foo in a header file so we can use it in multiple translation units. Everything I've read suggests that by using extern exactly once instructs the compiler to provide the implementation in the unit where extern is encountered (or where inline is missing). This would be inline.c in the attached. I tried: extern inline void e_foo(); extern void e_foo(); void e_foo(); In all those cases, there is no implementation of e_foo in the asm file. If we provide a full re-definition of e_foo() with extern inline in inline.c (as in the forum thread above) we get 'e_foo' already has body. The only way I managed to make it work was by defining in inline.c and removing the inclusion of the header. Is this a bug or have I mis-interpreted something? Everything here is with SDCC : mcs51 3.2.1 #8039 Example using --std-c99 --stack-auto As ever, thanks for your time and help George |