Thread: problem using pointer

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    1

    problem using pointer

    what would cause the address saved in a pointer been changed when I am not doing any operation on that pointer?

    consider the following situation:

    I have 2 pointers, let's say a and b.
    a points to a address which is acquired by malloc, let's say 0x100ef
    and now, when I am doing some operation on pointer b, the address that is pointed
    by a is suddenly changed, let's say a is pointing to 0x0033 now.

    Is there any special details that I should take care when using pointer which I missed?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I could think of a few things I suppose (scope issues, fiddling with b when b points to a), but it would be easier to tell if you could cough up some details, ideally the actual code.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by ptmstart View Post
    what would cause the address saved in a pointer been changed when I am not doing any operation on that pointer?
    Assuming there isn't a compiler bug involved (compiler bugs happen in approximately 1 in a million of these cases), the reason that a pointer is modified when another pointer is changed is because the second pointer holds the address of the first pointer - either on purpose or by accident.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Buffer overruns are a good example: http://cpwiki.sf.net/Buffer_overrun
    It you want to get to the bottom of it, it can take some good debugging. Fortunately, Visual Studio can help you catch these bugs very, very easily.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pointer to pointer realloc problem
    By prakash0104 in forum C Programming
    Replies: 14
    Last Post: 04-06-2009, 08:53 PM
  2. Another pointer problem
    By mikahell in forum C++ Programming
    Replies: 21
    Last Post: 07-20-2006, 07:37 PM
  3. Pointer problem
    By mikahell in forum C++ Programming
    Replies: 5
    Last Post: 07-20-2006, 10:21 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. pointer problem
    By DMaxJ in forum C Programming
    Replies: 4
    Last Post: 06-11-2003, 12:14 PM