Thread: may address of a variable be null

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    17

    Question may address of a variable be null

    hi guys,

    i have a variable like this:
    Code:
    ULONG cfgReg=0;
    may &cfgReg be NULL?

    it wont happen usually but in a very extreme situation? if there is no memory for 64bits?

  2. #2
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    In this case, taking the address of a declared variable, you should never get a NULL address as the address is either on the stack (if you run out of stack space you have other problems) or in the data section of the code. Memory allocation has nothing to do with it.

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    > may address of a variable be null
    No.
    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.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    37
    I totally agree with Salem,

    Variable decleared cannot be without address.

    You can have pointer and initalied to NULL.
    like, int *p=NULL;
    which would mean the p is a pointer to int but is not pointing to anything .

  5. #5
    Registered User
    Join Date
    May 2003
    Posts
    17
    then can i declare millions billions of variables and run them?
    cant system reject your request?

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you've got enough stack space, sure. Otherwise, as long as you have enough ram and/or hard disk(swap) space to keep making variables dynamically, sure. Otherwise you'll run out of memory and malloc will fail and tell you as much.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. "Virtual Printer" or "Moving Printjobs"
    By extasic in forum Windows Programming
    Replies: 12
    Last Post: 06-30-2011, 08:33 AM
  2. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  5. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM