質問

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