What is at address 0?

This is a discussion on What is at address 0? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; 0 is an address, but you can't reference it. What is at address 0? If address 0 holds something useful, ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    224

    What is at address 0?

    0 is an address, but you can't reference it. What is at address 0? If address 0 holds something useful, how can a program access it?

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >What is at address 0?
    Stuff you're not supposed to access. Duh.
    My best code is written with the delete key.

  3. #3
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    The leprechaun lives there, if you can reference him he'll give you his pot of gold.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
    #define NULL 0 //here be dragons
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >#define NULL 0 //here be dragons
    NULL isn't necessarily address 0. Neither is a null pointer.
    My best code is written with the delete key.

  6. #6
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,575
    Quote Originally Posted by Yasir_Malik
    0 is an address, but you can't reference it. What is at address 0? If address 0 holds something useful, how can a program access it?
    Memory at location 0 is reserved by the operating system. Programs cannot access it. So you can't access it.

    The fact you can address 0 (the so called null pointer) is simply a language implementation. It is not pointing to memory address 0. The C++ implementation uses this syntax instead to define a pointer that is pointing to nothing. And it was safe to do so by the language implementators exactly because memory address 0 cannot be accessed.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  7. #7
    BMJ
    BMJ is offline
    Banal internet user BMJ's Avatar
    Join Date
    Aug 2002
    Location
    Chicagoland
    Posts
    1,380
    Quote Originally Posted by Yasir_Malik
    0 is an address, but you can't reference it. What is at address 0?
    Bits, silly.

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by Mario F.
    And it was safe to do so by the language implementators exactly because memory address 0 cannot be accessed.
    Depends. Old non-protected-mode OSs sometimes actually had stuff there. Like the interrupt table. Dereferencing NULL brought total havoc. It was used for fast checking, not for actual safety.

    Quote Originally Posted by BMJ
    Bits, silly.
    Not necessarily. Modern OSs use virtual address spaces. Thus each address in your application can be mapped to something totally different in real memory. Address 0 is mapped nowhere - so there aren't any bits there.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Quote Originally Posted by Yasir_Malik
    0 is an address, but you can't reference it. What is at address 0? If address 0 holds something useful, how can a program access it?
    I think I've seen this mentioned as one possible way. (Well, something like this -- it makes for good Googling.)
    Code:
    p == (type *)(0,0);
    But on systems in which address 0 contains something interesting and useable, the usual NULL pointer issues may be dealt with in non-standard ways.

    [edit]I think this is what I may have found a while ago.

    [edit=2]Finally found old post.

    Quote Originally Posted by Dave_Sinkula
    [sorta]RE[/sorta]

    What I found to be an interesting sidebar one day was seeming to recall an '08 that had its PORTA located at address zero. It had been too long for me to recall details of how such a critter was handled, and I still don't recall exactly how it was handled -- I think it just had to wander off the standard a bit.

    Because eventually a question arises: How might one create a compile-time constant to represent a pointer to address zero (if such a thing were truly of use)? This of course given that, per the standard, a compile-time constant that evaluates to zero must be a null pointer.

    I googled some clc and found some trickiness that could attempt to accomplish this. [...] I'll spare you some searching: click.

    But overall, I thought it was interesting that, perhaps in an unintentional way, (bad?) software programmers have seemingly dictated that a hardware designer never put anything useful at address zero because the C standard doesn't allow a clean way to escape it being a null pointer.
    And
    Quote Originally Posted by Dave_Sinkula
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Nerds.
    Woop?

  11. #11
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    The real-mode interrupt vector table starts at 0000:0000 and is always there regardless if the CPU is in protected mode or not.

    And you can make a pointer to 0000:0000 but it won't do anything special. Address 0000:0000 is the low WORD of the first interrupt handler. You used to be able to manually patch into the IVT, but you are not allowed to in protected mode and this has nothing to do with Windows and everything to do with Intel.

    I recommend looking at Randall Hyde's Art of Assembly book where he discusses the IVT and how to patch it VIA DOS int 21h and via your own code. Patching via your own methods was not advisable in the day due to the fact that, even though it would work, the OS had no knowledge of you patching into the interrupt chain which could cause issues later. The C functions that used to use DOS int 21h for the purpose of installing/uninstalling interrupt handlers was setvect() and getvect(). Of course these functions reside in dos.h and are only compatible with MS-DOS.

    In a DOS session under XP, you are still allowed to patch the IVT either manually or through DOS int 21h.

  12. #12

    Join Date
    May 2005
    Posts
    1,041
    and everything to do with Intel.
    I don't by any means have anywhere near the assembly programming experience that you do, but from my brief flirtations with various instruction sets I've found that although Intel is the chief market big guy, it's instruction set is built on a series of hopeless hacks and kludges just waiting to explode.

    Feel free to elaborate?!
    I'm not immature, I'm refined in the opposite direction.

  13. #13
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,070
    I hate assembly. Reminds me of the time I tried to write an OS kernel. *shudders*
    Memorial University of Newfoundland
    Computer Science

    Mac and OpenGL evangelist.

  14. #14
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,575
    I think people who code in assembly are cool. It's the ones that actually like doing it that scare me.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  15. #15
    Registered User
    Join Date
    Aug 2001
    Posts
    244
    i like assembly... but in my eyes c is a macro assembler *g* (c++ is maybe a bit too sophisticated for that view )

    edit: well and with the intrinsics its easy writing assembler code that looks like c-code.
    Last edited by Raven Arkadon; 07-14-2006 at 06:40 PM.
    signature under construction

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does this do (Windows API)?
    By EVOEx in forum Windows Programming
    Replies: 4
    Last Post: 12-19-2008, 10:48 AM
  2. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 06:06 PM
  3. I thought pointers were pointers...
    By keira in forum C Programming
    Replies: 19
    Last Post: 08-16-2007, 12:48 AM
  4. DX - CreateDevice - D3DERR_INVALIDCALL
    By Tonto in forum Game Programming
    Replies: 3
    Last Post: 12-01-2006, 07:17 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21