Thread: Memory addressing question

  1. #16
    Join Date
    Jul 2009
    Quote Originally Posted by CommonTater View Post
    In C, nothing is implicitly initialized.

    If you want "int A = 0;" you have to say so.
    Quote Originally Posted by Paragraph 6.7.8, clause 10, of C99.
    If an object that has automatic storage duration is not initialized explicitly, its value is
    indeterminate. If an object that has static storage duration is not initialized explicitly,
    if it has pointer type, it is initialized to a null pointer;
    if it has arithmetic type, it is initialized to (positive or unsigned) zero;
    if it is an aggregate, every member is initialized (recursively) according to these rules;
    if it is a union, the first named member is initialized (recursively) according to these
    Now, as I'm reading it, a global (static duration) array (aggregate) of int's (arithmetic type) will be initialized to all 0. Please correct me if I'm wrong.

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Yes, you are correct msh
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Portland, OR
    Quote Originally Posted by Elysia View Post
    We are not discussing non-OS here. All the information provides thus far is with regards to a modern operating system with virtual memory addressing. In which case, it doesn't matter.
    If you strip away that, then there are simply no rules regarding what is relative to where or how.
    There is more than one way to implement virtual memory. The most common technique is paging, but there is also segmentation. Intel processors actually support both, in fact you can use both of them at the same time if you want.

    Thus, a virtual address is always "relative to" some segment. The x86 processor provides 6 segments which can be simultaneously addressed. Traditionally these are called code, data, stack, extra, F, and G. That's what the OP meant by "extra segment."

    Now, in reality, most OSs will set all six segments to begin at 0 and extend to the top of physical memory. This disables segmentation for all intents and purposes so you don't have to think about it. But the segments are still there and the addresses are still relative to the segments.

    On an embedded platform, the physical addresses can be important. On a PC they are almost never important unless you are writing a device driver. A piece of data could be located at one physical address at one instant, then a completely different physical address a moment later (think about swapping).
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer memory question
    By Edo in forum C++ Programming
    Replies: 5
    Last Post: 01-21-2009, 03:36 AM
  2. Memory question
    By John_L in forum Tech Board
    Replies: 8
    Last Post: 06-02-2008, 10:06 PM
  3. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  4. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM