# Windows C/C++ question (memory segments)

**URL:** <https://boards.straightdope.com/t/windows-c-c-question-memory-segments/462712>\
**Category:** Factual Questions\
**Created:** [September 9, 2008, 1:12am UTC](https://boards.straightdope.com/t/windows-c-c-question-memory-segments/462712 "2008-09-09T01:12:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [September 9, 2008, 1:12am UTC](https://boards.straightdope.com/t/windows-c-c-question-memory-segments/462712/1 "2008-09-09T01:12:49Z")

</div>

I want to figure out at runtime whether a particular address is in the .bss segment or the .code segment or what. Are there symbols of some sort called **start\_bss** or **BSS\_START** or anything of that sort that I can use to figure out what segment the address is in?  
thanks

---

<div class="post-metadata">

**Author:** ![Henrichek](https://avatars.discourse-cdn.com/v4/letter/h/5daacb/32.png) [@Henrichek](https://boards.straightdope.com/u/Henrichek)\
**Post date:** [September 9, 2008, 9:40am UTC](https://boards.straightdope.com/t/windows-c-c-question-memory-segments/462712/2 "2008-09-09T09:40:42Z")

</div>

I believe it depends on which linker you use. As an example, GNU’s linker provides some symbols by default, such as \_\_bss\_start and \_end. Although it’s easily configurable by providing different linker scripts. What linker do you use?

---

<div class="post-metadata">

**Author:** ![Sage\_Rat](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/sage_rat/32/399_2.png) [@Sage\_Rat](https://boards.straightdope.com/u/Sage_Rat)\
**Post date:** [September 9, 2008, 12:19pm UTC](https://boards.straightdope.com/t/windows-c-c-question-memory-segments/462712/3 "2008-09-09T12:19:49Z")

</div>

I suspect that your answer will be rather dependent on what compiler/linker you use. I don’t recall seeing anything standardized, but the POSIX C header list is admittedly larger than one would think and I don’t feign to have memorised it.

Not knowing what you’re doing such that you would need to know this, you might want to look at [this site](http://users.bestweb.net/~ctips/) to see if it doesn’t suggest some techniques to prevent memory issues.

---

<div class="post-metadata">

**Author:** ![MaxTheVool](https://avatars.discourse-cdn.com/v4/letter/m/9fc29f/32.png) [@MaxTheVool](https://boards.straightdope.com/u/MaxTheVool)\
**Post date:** [September 9, 2008, 5:39pm UTC](https://boards.straightdope.com/t/windows-c-c-question-memory-segments/462712/4 "2008-09-09T17:39:05Z")

</div>

> [@Henrichek](#):
>
> I believe it depends on which linker you use. As an example, GNU’s linker provides some symbols by default, such as \_\_bss\_start and \_end. Although it’s easily configurable by providing different linker scripts. What linker do you use?

The Microsoft Visual Studio linker. I spent a long time poking around in the documentation on [msdn.com](http://msdn.com) and couldn’t find anything, but I’ve found that documentation to be woefully badly organized.

---

<div class="post-metadata">

**Author:** ![Sage\_Rat](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/sage_rat/32/399_2.png) [@Sage\_Rat](https://boards.straightdope.com/u/Sage_Rat)\
**Post date:** [September 9, 2008, 11:15pm UTC](https://boards.straightdope.com/t/windows-c-c-question-memory-segments/462712/5 "2008-09-09T23:15:41Z")

</div>

I’d probably just recommend having Visual Studio spit out the map file when you compile, and then read that in and parse it. You might need to figure out the offset that the addresses have been converted to when loaded into memory, but that should just be a matter of, for instance, looking at the position of main() in the map file and the address location in runtime and storing the difference.

Other things to try are:

1. Use an assembler block and check if MASM has any way to access the address of the segments, and pass the results back.

void\* bss\_loc;  
\_\_asm {  
mov bss\_loc, @DATA  
}

or something like that.

1. See if the pragmas like bss\_seg(), when you do a push command to a label, whether you can access that label outside of the pragma. (I suspect not, but who knows.)
