Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 1
    The first 3 bullets most definitely take place before runtime, i.e., during compilation. The 4th bullet should also take place during compilation, assuming a decent compiler is in use (since the address of the constant string is well known at this point). Perhaps you meant to say "here's what your compiler will do at run time" (its own runtime)... Commented Aug 11, 2015 at 21:45
  • @barakmanos I had in mind that the locations in (virtual) memory actually get "allocated" when the program is loaded. However, a lot of what happens in the first three bullets is decided at compile time, whereas corresponding actions for the second example might only be decided when the program actually runs.
    – David K
    Commented Aug 11, 2015 at 21:49
  • locations in (virtual) memory actually get "allocated" when the program is loaded - that's an OS issue, which is unrelated to (and independent of) the program. In other words, the program "knows" nothing about it. As far as it "concerns", that string is allocated at the RO data section of the executable image. Of course, the actual (physical) address of that string maybe different every time the OS creates a process and loads it into memory. But it's like saying that the program may be running at a different place around the world, depending on where your computer is located. Commented Aug 11, 2015 at 21:55
  • More similar to const char s_buffer[10] = "my String"; Commented Aug 11, 2015 at 21:58
  • @Potatoswatter Thanks, I had momentarily considered the const, but omitted it for some reason. It is a better example as a const string (with corresponding changes to what the programmer can or can't do).
    – David K
    Commented Aug 11, 2015 at 22:19