Bizarre problem!

This is a discussion on Bizarre problem! within the C Programming forums, part of the General Programming Boards category; An access violation sounds like you're running out of bounds on your arrays. An access violation is you trying to ...

  1. #16
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    An access violation sounds like you're running out of bounds on your arrays. An access violation is you trying to access some block of memory you shouldn't be accessing.

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

  2. #17
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    I know, but I've checked and double checked it and can't seem to find any that are erranous, I've examined the entire variable 'g_table[x]' and all it's values are in bounds and as they should be; I've also compared sizeof(g_table[x]) with sizeof(TABLE) and these are identical.

    Plus, I don't see how simply calling a function would produce this error; as far as I am aware there is no writing to my variable in the function call, except to pass the variable to the function (if that makes sense).

    So I'm guessing that the error occurs in between the two lines of code:

    Code:
    1. g_table[x] = MyFunction(g_table[x]);
    // error here?
    2. TABLE MyFunction(TABLE table){...}
    Well, I don't really have a clue, I usually resolve Access Violations without much bother but this one has really got to me!
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  3. #18
    Nick
    Guest
    Code:
    typedef struct
    {
    	PLAYER player[MAX_PLAYERS];
    	int pot,
    		dButton,
    		nPlayers,
    		nActivePlayers;
    	BLINDS blinds;
    	BOOL visible; 
    	BOOL active;
    	BOOL suspended; 
    } TABLE;
    Since your passing one of these by value, player
    gets copied as well. Try passing a TABLE*.

  4. #19
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    Yes, thats what I've done to fix it (it makes more sense anyway!).

    Would copying 'player' neccessarily produce an error though, cos I checked each 'player' in the variable and they were all ok?
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  5. #20
    Nick
    Guest
    I've heard of people getting segfaults doing stuft like
    this with large arrays.

  6. #21
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    Oh cool, perhaps thats it, that kind of thing seems the only plausible reason to me; I take it a 'segfault' is to do with allocating/ copying memory?
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  7. #22
    Nick
    Guest
    A segfault is when you access memory that your program
    doesn't own.

  8. #23
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    Oh, sorry, gotcha (an access violation), I'm not to hot on terms of things!

    Thanks for the help, I feel more at ease about using my structure now.

    dt
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

  9. #24
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    > When I used the Turbo debugger from Borland and stepped through the code
    Mmmm....
    I thought you were building a windows application

    Which compiler are you using.

    > The size of the struct is 7724
    Ouch!

    My guess is you've outgrown the stack in one easy step. Since you started with
    TABLE PlaySeenHand(TABLE);
    There would be two of these on the stack (one for the parameter, one for the return result).

  10. #25
    Anal comment spacer DominicTrix's Avatar
    Join Date
    Apr 2002
    Posts
    120
    > Mmmm....
    > I thought you were building a windows application

    I am, didn't realise that would be a problem! (I'm using debuggers for the first time and finding them very confusing). I'm using Dev-C++, I quite like the debugger with that but I couldn't get any error codes that I could find the meaning of so I tried the Turbo one and it seemed to work ok.
    My guess is you've outgrown the stack in one easy step. Since you started with
    TABLE PlaySeenHand(TABLE);
    There would be two of these on the stack (one for the parameter, one for the return result).
    Brilliant, thanks, that seems to be the only thing that makes sense! I love bugs like this, you learn so much more trying to fix them!

    dt
    "The most important thing about acting is honesty. If you can fake that you've got it made" - George Burns

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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