C and #defines

I am working on an embedded system, so memory is valuable to me.

One of the problems that repeated itself is that I ran out of free space while trying to compile a program for it. This is usually fixed by limiting the number of typedef, etc., which can take up a lot of space.

There is a macro generator that I use to create a file with lots of #define. Some of them are simple values, others are boundary checks.

t

#define SIGNAL1 (float)0.03f
#define SIGNAL1_ISVALID(value) ((value >= 0.0f) && (value <= 10.0f))

Now I do not use all these definitions. I use some, but not most. I was told that in fact they do not occupy any memory if they are not used, but I was not sure about it. I hope that by cutting out the unused ones, I can free up additional memory (but again I was told that this is pointless).

Unused #define takes up any memory space?

+3
source share
4 answers

No, #defines do not take up space if they are not used - #defines work like find / replace; whenever the compiler sees the left half, it will replace it with the right half before it compiles.

So, if you have:

float f = SIGNAL1;

The compiler will literally interpret the statement:

float f = (float)0.03f;

SIGNAL1, ..

+16

typedef .., .

, typedef . . (typedef'd ), , , . , " .." .

, , .

, :

  • (/-)
  • ( ++)
  • , ( ).

, , () (Flash/EPROM).

- / , . , . , . , , .

. C- ( ) , .

, . 64 2 Flash, . ( SRAM, ). , , , . , / - , , (.. , ).

Clifford

+4

, .

, #defines .

Yes, all #defines (used or not used) should be known to the compiler when creating the binary.

For your question, it's a bit ambiguous how you use the compiler, but it almost seems like you're trying to build directly on an embedded device; have you tried the cross compiler? :)

0
source

unused #defines does not take up space in the resulting executable. They occupy memory in a compiler that compiles whist.

0
source

Source: https://habr.com/ru/post/1716278/


All Articles