K
K
kacejot2017-09-26 21:55:51
C++ / C#
kacejot, 2017-09-26 21:55:51

What memory does a string literal go to?

I've heard that literals and constants end up in the readonly memory section of an object file when they are built. It turns out that for the expression: the literal will not be put on the stack?
foobar("sample text");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SolidMinus, 2017-09-26
@kacejot

It won't fit, right. A pointer to the readonly section will be passed:

lea eax, [Адрес]
push eax
call foobar

In some cases, if the case is passed to a pointer, the optimizer may optimize into a read-write section. In some, maybe. gcc doesn't exactly do that, so I don't recommend modifying a string literal without modifying permissions :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question