문제

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