How much memory does a Macro definition take?

I have a lot of unused macros in my code. So, I'm curious. If the macro is not used, does it take up memory in your program?

The type of macros that I have are just the main ones. Example:

#define TEST_ID 0
+4
source share
3 answers

Macros will be expanded during the pre-processing so that they do not exist in your program. They just take up some space in the source code.

Edit:

In response to Barmara’s comment, I did some research.

MSVC 2012: in a debug build (when all optimizations are disabled, / Od) adding macro lines will not increase the size of your program.

GCC: , . . . ( . , @, @)

+5

, , , :

#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("%d %s\n", argc, argv[0]);
    return 0;
}

#include <stdio.h>

#define TEST_ID 0

int main(int argc, char *argv[])
{
    printf("%d %s\n", argc, argv[0]);
    return 0;
}

ASM, gcc -S, .

+2

the macro is replaced by the preprocessor before starting compilation. if you define a macro and do not use it, the compiler will never see it.

+1
source

All Articles