D
D
Denis Bredun2020-07-14 11:39:57
C++ / C#
Denis Bredun, 2020-07-14 11:39:57

Where is the data written that such and such a variable is a constant?

For example, we have code:

const int i = 5;
const string g = "6";

Where is it shown in memory or marked in metadata that these variables are constants? How is it labeled under the hood?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ayazer, 2020-07-14
@Luffy1

You already asked: Where in an instance of a primitive reference type, such as string, is the information that this instance is a constant?
when the code is already compiled, it is not stored anywhere. we just have the values.
during compilation - it is stored like this https : //github.com/dotnet/roslyn/blob/7a836c8e5a06... /7a836c8e5a06... But again, this is only necessary for the compiler to know what to do with these values. As a result, the values ​​of the constants will be substituted for all places of use (which you can easily verify by decompiling the code)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question