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++.

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top