Hi George, > 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?
No, you're not. SDCC is just not yet smart enough as was also written in the forum thread you mentioned. > 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? As long as every instance is inlined the linker won't need the external implementation. But as soon as the external implementation is really used (called or assigned to a function pointer) the linker will complain that it cannot find it. So it does not enforce the rules set by the standard. For comparison: the linker also does not require you to provide main. > 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? This may be a bug. I have not looked deeper into it yet. > 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 Maarten ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user