Comiler discards unused code (subs)?

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Aresby
Posts: 64
Joined: Fri Mar 16, 2012 8:35 am
Location: Milton Keynes, UK
Contact:

Comiler discards unused code (subs)?

Post by Aresby » Sat Mar 24, 2012 10:04 am

I'm using a couple of the "include" type files that add considerably to my final code size. The USART module adds about 2K to my program byte size, for example, and over 200 variable bytes.

Does the compiler recognise that a large portion of an include file is never used/referenced and discard that code or is everything compiled regardless?

If the latter I suppose the answer is to make one's own library from the provided include file, and only keep the routines actually used, is this right?
Aresby
Swordfish & PIC Newbie

Jerry Messina
Swordfish Developer
Posts: 1473
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Post by Jerry Messina » Sat Mar 24, 2012 11:35 am

It discards any unused/unreferenced routines and variables, so you don't have to worry about them using up space.

The usart module itself probably isn't adding all that much. Do you use a lot of string data? What you may be seeing is all the overhead associated with them.

SF has very powerful string handling capability, esp compared to something like C. You can mix ram and rom strings, perform operations on them, etc. All of that comes at a high cost, however. If you look behind the scenes, you see a lot of string copying and temp strings used to get all that flexibility.

There are ways around that, but you have to be willing to do a lot of work yourself.

Post Reply