Thread: Access violation writing location 0x00000004.

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    29

    Access violation writing location 0x00000004.

    Hi all
    I have this code that appears to be simple enough

    Code:
    #define TEST_LIMIT 100
    	.
    	.
    	.
    
    struct menu_info {	
    	long rpt_options;	
    	long rpt_default;	
    	char **narr_menu;	
    	char **plot_menu;	
    	char **eqns_menu;	
    	char **cust_menu;	
    };
    	.
    	.
    	.
    
    	struct menu_info *M[TEST_LIMIT];
    	.
    	.
    	.
    
    void main(int argc, char **argv)
    {
    	.
    	.
    	.
    
    	for(i = 0; i < TEST_LIMIT; i++)
    		M[i]->rpt_default = 0L;
    on the first iteration (i.e i=0) I get this message:
    Unhandled exception at 0x013d3406 in myprogram.exe: 0xC0000005: Access violation writing location 0x00000004.

    Before getting into the for loop, M appears to be correct and pointing to where it supposed to.

    Any clue anybody?
    Thanks
    ZA

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Yeah, post the part where you allocate M[ i ] before trying to dereference it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    29
    Thank you
    I think I've found the issue with the allocation
    ZA

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 08-13-2008, 02:51 AM
  2. Access violation when reading a string.
    By Desolation in forum C++ Programming
    Replies: 16
    Last Post: 05-01-2007, 10:25 AM
  3. Access Violation?
    By rwmarsh in forum C++ Programming
    Replies: 6
    Last Post: 05-04-2006, 10:56 AM
  4. Access violation writing location 0x00000000
    By bennyandthejets in forum Windows Programming
    Replies: 9
    Last Post: 04-14-2004, 03:59 AM
  5. Strange access violation
    By jimmy_anttila in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2004, 03:10 AM