C memory space and #defines
c, embedded, memory-management
Solution
No, #defines take up no space unless they are used - #defines work like find/replace; whenever the compiler sees the left half, it'll replace it with the right half before it actually compiles.
So, if you have:
float f = SIGNAL1;
The compiler will literally interpret the statement:
float f = (float)0.03f;
It will never see the SIGNAL1, it won't show up in a debugger, etc.
Problem
I am working on an embedded system, so memory is precious for me. One issue that has been recurring is that I've been running out of memory space when attempting to compile a program for it. This is usually fixed by limiting the number of typedefs, etc that can take up a lot of space. There is a macro generator that I use to create a file with a lot of #define's in it. Some of these are simple values, others are boundary checks ie ``` #define SIGNAL1 (float)0.03f #define SIGNAL1_ISVALID(value) ((value >= 0.0f) && (value <= 10.0f)) ``` Now, I don't use all of these defines. I use some, but not actually the majority. I have been told that they don't actually take up any memory if they are not used, but I was unsure on this point. I'm hoping that by cutting out the unused ones that I can free up some extra memory (but again, I was told this is pointless). Do unused #define's take up any memory space?