Differences between SRC += s65.c and #include "s65.c''

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
I'm using glcd library for lcd from siemens s65 (http://www.superkranz.de/christian/S65_Display/data/s65_glcd_V01.zip)
In file s65.c I have my funcions based on library. In makefile I have added

LDFLAGS += -lm -L../glcd/. -lglcd

All works, but when I add s65.c to makefile

SRC += s65.c

code is 1900B (!) bigger than when I remove it from makefile and only include in main.c (device also works)

#include "s65.c"

I know it's bad, but 1900B is for uC quite big :>.
What's the problem? What's the difference between SRC += s65.c and #include "s65.c"?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't follow. Your use of -lglcd to link with libglcd.a suggests that the functionality is already in a library so why do you need a .c file added to the build too?

As for the difference. I guess it's possible that by #including the compiler was able to inline optimise some of the code but this would only really work if the functions were "static inline" and, if that were the case, it wouldn't have made sense to use SRC+=s65.c anyway.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would guess that there is conditional code in s65.c
You probably end up with some unnecessary default stuff when you compile a separate module.

Build both versions, and then do a avr-nm -n on the elf files. Or perhaps just do a avr-nm -n of main.o and s65.o

You should see where the code size differences have come from.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the answer!

Quote:
I don't follow. Your use of -lglcd to link with libglcd.a suggests that the functionality is already in a library so why do you need a .c file added to the build too?

In s65.c (it isn't file from glcd library, it only uses it) I have f.e. function which draws 100 random lines. So it must be included.
Quote:
Build both versions, and then do a avr-nm -n on the elf files. Or perhaps just do a avr-nm -n of main.o and s65.o

Ok I will check it.

Edit:
I found "000000000 r f15x22" (array with font) I have in main.o and s65.o, so I put function which is selecting font only to one file and it works :). It looks that before that whole array with font was in two separate *.o files. Thanks!