Unused defines... do they take up space?

Consider me like a child, because I really don't know how much of any of this works :slight_smile:

I have a 3D printer that has custom firmware that I'm trying to use, but it won't quite fit on the chip my printer has. The firmware developers have this helpful tidbit:

if the program won't fit, remove unused portions of the firmware

Uh-huh.

Anyway, I opened it up and started poking around, and I see (for example) about 200 defines for various boards that this firmware supports. Here's an example:

#define BOARD_GEN6 5 // Gen6

Question a) Can I safely remove the other 199?
Question b) Will that actually save any space?

So I figured I could just try it. It compiled fine, but no it didn't save any space.

bcsteeve:
So I figured I could just try it. It compiled fine, but no it didn't save any space.

google C++ preprocessor directives

Thanks!

The define itself takes no space but the code controlled by the define very well might. So you need to dig into the source code and see what it does. Often you will see configuration options controlled by defines. Sometimes you can comment the define out to disable a specific optional feature.

bcsteeve:
I have a 3D printer that has custom firmware that I'm trying to use, but it won't quite fit on the chip my printer has. snip

Question a) Can I safely remove the other 199?
Question b) Will that actually save any space?

As others have already said: a) Yes, b) No, so there is no point in removing them

As pert says, some #defines turn on or off program options which may increase or decrease the program size.

One thing that can take up a lot of program space is text strings... things like:

  SomeSortOfPrintStatement("Printer is now ready");

If you shorten the messages (e.g. to just "Ready"), that will save program space

Yours,
TonyWilk

Thanks for the tip!