Null pointer assignmnet error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agsupriya86
    New Member
    • Mar 2007
    • 34

    Null pointer assignmnet error

    Hello!

    i wanna know about the illfamos null pointer assignmnet error..when can we face such an error and how do we debug it??
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Originally posted by agsupriya86
    Hello!

    i wanna know about the illfamos null pointer assignmnet error..when can we face such an error and how do we debug it??
    You make sure that your pointer is pointing to something that you can assign. If you try to assign something to NULL it gets NULL. If you are trying to assign a NULL pointer to something then you should not have a problem.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      Use an assert.

      At the desired place in the code assert that the pointer is not null. If it is, the code will break at the assert during execution.

      Comment

      • agsupriya86
        New Member
        • Mar 2007
        • 34

        #4
        Originally posted by RedSon
        You make sure that your pointer is pointing to something that you can assign. If you try to assign something to NULL it gets NULL. If you are trying to assign a NULL pointer to something then you should not have a problem.

        Im still not clear about the concept behind the error..I wanna know why this error occurs and how can we debug it??

        Comment

        • weaknessforcats
          Recognized Expert Expert
          • Mar 2007
          • 9214

          #5
          Originally posted by agsupriya86
          Im still not clear about the concept behind the error..I wanna know why this error occurs and how can we debug it??
          This is the same error as being told to go to a particular address in your city for a party but the piece of paper (the pointer) that has the address of the party is blank.

          Generally, you do not debug null pointers. Instead, you test pointers for null before using them. A non-zero value in a pointer is assumed valid.

          Use those asserts.

          Comment

          • RedSon
            Recognized Expert Expert
            • Jan 2007
            • 4980

            #6
            Originally posted by agsupriya86
            Im still not clear about the concept behind the error..I wanna know why this error occurs and how can we debug it??
            It's not an error to debug. If you want to avoid having null pointer errors make sure that your pointers are not null, its very simple. You should be careful that your pointers do not point to random space in memory that could be very bad and is a common beginner programming mistake.

            Comment

            Working...