Question

In C, in terms of the amount of memory used, if there are a bunch of functions all with return 1;, is each 1 literal stored or just one 1?

I.E. would it be better to use (at file scope) static const int numOne = 1 and then have the functions use return numOne;?

In case it is compiler dependent, I am compiling for a TI MCU using TI's C28x compiler.

Please note this question is about C not C++.

Was it helpful?

Solution

No, usually literals aren't "stored" at all. In particular small integer constants as this one usually go into immediates for the assembler, they are directly in the code, not in some data section.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top