[C++] Memory/executable size question

Including it in a .cpp file makes the compilation unit larger (and hence the final executable and memory size) only by the enums/consts actually used in the .cpp file or by all the enums/consts defined in the "enums.h"?

Re: [C++] Memory/executable size question

Generally speaking the compiler is smart enough to know that you didn't reference the variable anywhere in the .cpp and the memory usage of your application should not be any larger. The binary will slightly larger as that code will be in there.

Re: [C++] Memory/executable size question

I could be wrong, but if I understand the C++ compile process correctly, the enum won't make any difference whatsoever unless you have debugging symbols set. The C preprocessor will just substitute instances of the enum to its appropriate value, e.g.:

Re: [C++] Memory/executable size question

I think enums are type-checked, so it's not done by the preprocessor. But you're right that it should make no difference whatsoever to the generated code. Enumeration constants are just that, constants -- they don't incur any overhead over an integer literal.

Re: [C++] Memory/executable size question

it is correct that enums are not preprocessed, they only represent integers which are (in x86 at least) directly representable in machine code, so no explicit load from memory is required and they should not increase the executable size by much (depending on the size of the number)