hkBattousai
hkBattousai

Reputation: 10931

C18: Do unused library functions consume space in EPROM?

Library.h

void Foo1(void);        // Unused
int  Foo2(int, int);    // Used
char Foo3(char);        // Unused

main.c

// ...
#include "Library.h"
// ...
void main(void)
{
    int ret;
    // ...
    ret = Foo2(3, 7);
    // ...
}

I have a library file which has a lot of function definitions in it. Will the generated machine code size increase because of the unused library functions? Or will the compiler optimize the code by ignoring those unused functions?

IDE: MPLAB 8.43
Compiler: MCC18 3.34
PIC: 18F2550

Upvotes: 3

Views: 291

Answers (2)

anup shah
anup shah

Reputation: 1

For C18 member in lib is .o - so if your link requires one function from a member the whole (all functions from) .o is included in final bin/hex code.

Upvotes: 0

Carl Norum
Carl Norum

Reputation: 224972

  1. Check. Use a disassembler or some other tool to look at your output binary and find out.
  2. Find out if your linker has an option to do dead-stripping.

Upvotes: 2

Related Questions