+10

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?

7/16/2017 11:28:12 PM

jay

3 Answers

New Answer

+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.

+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..

+4

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.