> Hi,
>
> I have been using the SDCC compiler fora n 8051, and my goal is to
> optimize code size.
> I have noticed that when declaring a function as static inline, the
> function does get inlined in the resulting assembler code,
> but also the definition of that function is in there, so as a callable
> function, although this is used nowhere in the assembler code listing.
> This as a result wastes precious code space. Is there a way to optimize
> this function definition away?

Unfortunately SDCC is not able to detect that the static inline function
is never used non-inlined. That's why it always generates the callable
version.

> Using just inline (and not static inline)
> for a function works, but then I cannot use this header file with
> functions in a project with multiple c files.

I don't get this. Why would you not be able to use this header file in a
multi-source project? If all occurrences of the function are inline
without extern during compilation of a source file the compiler is not
allowed to generate an implementation with external linkage.

But if you use simple inline you only have to provide a non-inline version
to the linker. And if you place that in a library it will only be linked
in if it's really necessary. Here's an example:

Header.h:
inline int myfunc(int i) { return i; }

LibSource.c:
// possibly different implementation
extern inline int myfunc(int i) { return i; }

Or SaferLibSource.c:
// use the same implemenation
extern inline in myfunc(int i);
#include "Header.h"

ProjectSource.c:
#include "Header.h"
// This might get inlined, hopefully
int test1(int a) { return myfunc(a); }

// This cannot be inlined, it will need the one from [Safer]LibSource.c
int (*fp)(int) = myfunc;
int test2(int b) { return fp(b); }

This is how C99 defined this. But GCC by default works differently and you
need to tell it to adhere to the standard.

Maarten

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
Sdcc-user mailing list
Sdcc-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sdcc-user

Reply via email to