Home > Back-end >  The C language
The C language

Time:12-01

Char [b]="abcd";
The string came from a literal constant area is copy to the b in the array?
Still no literal constant area, is stored in the array b, directly?

CodePudding user response:

Personally think that is the copy to the b in the array,

"Abcd" is not a character, if it is a character, can consider to b is directly stored in the array,

CodePudding user response:

Compile a exe. Use od load, check the string, I think in the text segment,

CodePudding user response:

First code at compile time, after seeing the "abcd" string compiler, will give you put him in a fixed place [you all appeared in the process of the direct "string" ABC "... "is so], this place is called a static constant area,
At this point, the program, the exe [or DLL...]. There's an "abcd"
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Then the program executes, the CPU according to the meaning of this instruction, open up a char [] array on the stack space, set up according to the length of the surface of constant area "abcd \ 0", and then from the constant area the string copied
At this point, the program, this process, there is a "abcd" static constants [area], this thread stack, there is a space to array b, its content is "abcd \ 0"/copy of

CodePudding user response:

This is not necessarily, it and compiling optimization, related to the size of the amount of data,

CodePudding user response:

Copy the past thought from the constant area, specific need to see the assembly code

CodePudding user response:

references on fifth floor cool west wing response:
copy the past generally think from constant area, specific need to see if the disassembly code

That is probably from constant area copy the past, may be directly embedded into the instruction, that's difficult to say
  • Related