1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Why the program not crash when access NULL object?

Discussion in 'C' started by vql, Oct 12, 2007.

  1. vql

    vql New Member

    Joined:
    Sep 27, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    Please explain why the program is not crash when access to function PrintMe of object NULL. Please explain me clearly. Thanks.
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Because you compiler does find that function where p points.
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Because your compiler is not standards compliant (neither is MS) in this respect.

    Your use of the return type, "void", for main is also non-compliant.
     
  4. vql

    vql New Member

    Joined:
    Sep 27, 2007
    Messages:
    18
    Likes Received:
    0
    Trophy Points:
    0
    I think you are wrong because p is NULL pointer. The function also have a address, where p points to. But compiler can not know p's address -> so compiler also don't know the function's address.
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    If you are using MS compiler try using an F11 at the function call and see what happens
     

Share This Page