Segmentation Fault with PTR conversion

This is a discussion on Segmentation Fault with PTR conversion within the C++ Programming forums, part of the General Programming Boards category; Alright, Im using the g++ compiler on a rh9.0 linux machine. The main question is I converted my code to ...

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    47

    Unhappy Segmentation Fault with PTR conversion

    Alright, Im using the g++ compiler on a rh9.0 linux machine. The main question is I converted my code to use pointers instead of stack memory.
    Code:
    int *x = new int;
    I get the value and set the value by just calling *x with the asterisk. It seems to work but after a bit it gives a segfault and shuts down. Does anyone know what could cause this. It seems to mostly happen in for loops. Your help would be greatly appreciated. Thanks.

    My ForLoop Syntax for one of them:
    Code:
    for(*x=0;GetUser(*x-1)->next != NULL;*x++)
    {
    }

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,648
    You're incrementing the pointer and not the value.
    Code:
    (*x)++
    gg

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    47
    thank you sooooooo much!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help calling function is asm
    By brietje698 in forum C++ Programming
    Replies: 24
    Last Post: 12-06-2007, 03:48 PM
  2. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 01:54 PM
  3. Getting position from game..
    By brietje698 in forum C++ Programming
    Replies: 1
    Last Post: 10-26-2007, 12:15 PM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  5. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12:33 PM

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