+ 12

Globals, String literals Where are they stored?

Take for example cout << "Hello, World!" or #define ANumber 90 Where is this information stored? Is this all on the stack? or is there a special place for these?

16th Jul 2017, 11:28 PM
jay - avatar
3 Answers
+ 6
Special places*. This may be way more than you want to know, but this is a really nice coverage of what's actually going on in binaries: COMPILER, ASSEMBLER, LINKER and LOADER : A BRIEF STORY http://www.tenouk.com/ModuleW.html I don't know if it mentions these details, but DLLs (Windows) and SO (Linuxy) files work similarly. You can get a look at the various code sections with programs like dumpbin/PEBrowse (Windows), and readelf/objdump (Linux-like, Android, OSX). #defines I believe live in the compiler; as it turns out you can even write programs that run in the compiler itself (template codes)...but I'll have to dig for that link. * Special...for good reasons, like NX (No Execute)...so that trying to run code from .data causes a segfault / CPU exception.
17th Jul 2017, 12:23 AM
Kirk Schafer
Kirk Schafer - avatar
+ 7
Thanks Kirk! Perfect amount of info! Thanks aklex! This helps me also. Sorry for the late reply. Been working on my car half the day. Stupid heater hose busted and it was way up behind the motor.. Had to pull the friggen inlet manifold off to get to it. it was a mission..
17th Jul 2017, 6:32 AM
jay - avatar
+ 5
Constant globals or strings that do not change are stored in the .rdata section, which is read only. Your first hello world string example would be stored here And non-constant initialized strings / globals will be in the .data section They are not stored on the stack.
17th Jul 2017, 4:02 AM
aklex - avatar