Results 1 to 5 of 5

Thread: Unhandled exception

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Unhandled exception

    I get an Unhandled exception in c_test.exe: 0xC0000005: Access Violation error on the red bold line.

    .h file

    Code:
    #include <stdio.h>
    #include <string.h>
    
    typedef int	BOOL;
    
    #define fFALSE 0
    #define fTRUE  1
    
    typedef unsigned __int64 U64;
    
    #define filA 0
    #define filMAX 8		
    #define filIBD 16		
    #define rnk8 7
    #define rnkMAX 8		
    #define coWHITE 0		
    #define coBLACK	1
    
    #define coMAX 2
    
    #define pcPAWN	0		
    
    typedef struct tagPI
    {
      int pc;		
      int co;		
      BOOL fDead;	
    				
      int isq;	
    				
      int val;	
    } 
    PI, * PPI;
    
    #define cpiMAX	(filMAX * 2)
    
    typedef struct tagSQ
    {
      PPI	ppi;				
      int	isq;				
    } 
    SQ, * PSQ;
    
    #define csqMAX (rnkMAX * filIBD)
    #define cfMAX  16			
    
    typedef U64 HASHK, * PHASHK;					
    
    #define HashkSwitch(hashkDst)	((hashkDst) ^ 0x21D420B884CD6731)
    
    typedef struct tagSTE 
    {
      int coUs;			  
    } 
    STE, * PSTE;
    
    typedef struct tagCON
    {
      PI  argpi[coMAX][cpiMAX];		
      int argcpi[coMAX];		    
      SQ  argsq[csqMAX];		    
    } 
    CON, *PCON;
    
    #define IsqFromRnkFil(rnk, fil)	((rnk) * filIBD + (fil))
    
    BOOL FInitCon();
    .c file

    Code:
    #include <stdio.h>
    #include <stdarg.h>
    #include <stdlib.h>
    #include <string.h>
    #include <windows.h>
    
    #include "c_test.h"
    
    #include <ctype.h>
    
    int main(int argc, char * argv[])
    {
      if(argc > 1) 
      {
          return 1;
      }
    	
      FInitCon();
    	
      return 1;
    }
    
    BOOL FInitCon()
    {
      int k;
      int rnk;
      int fil;
    
      static CON s_con;
      
      PCON pcon = &s_con;
    
      PPI	ppi;
      int	pc;
      int	co;
    
      fil = filA;
      rnk = rnk8;
    
      for(k = 1; k < 50; k++) 
      {
    	switch(k) 
    	{
    	  case 9:
     	    pc = pcPAWN;
    	    co = coBLACK;
    lblSet:	
     	    ppi = &pcon->argpi[co][pcon->argcpi[co]++];
    
    	    ppi->pc = pc;
    	    ppi->co = co;
    
    	    ppi->fDead = fFALSE;
    	    ppi->isq = IsqFromRnkFil(rnk, fil);
    			
    	    pcon->argsq[ppi->isq].ppi = ppi;
    		
    	    fil++;
    	    break;
    	 
              case 1:
    	  case 2:
    	  case 3:
    	  case 4:
    	  case 5:
    	  case 6:
    	  case 7:
    	  case 8:
      	   goto lblSet;
        } 
      }  
    
      return fTRUE;
    }


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Unhandled exception

    and tracing through the code using the debugger shows the problem to be where?
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Unhandled exception

    Quote Originally Posted by 2kaud View Post
    and tracing through the code using the debugger shows the problem to be where?
    Are you serious? It's on the red bold line just like I stated in my post and the line is red.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  4. #4
    Fanatic Member 2kaud's Avatar
    Join Date
    May 2014
    Location
    England
    Posts
    996

    Re: Unhandled exception

    No, that line is where the problem is causing the exception. Its probably not where the problem is. Using the debugger to trace through the code will show where the values of the variables used in that line deviate from that expected. When tracing shows a variable to have a value other than that expected then you know where is the problem.
    All advice is offered in good faith only. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Unhandled exception

    OK, I understand and based on your explanation I found what caused it. I was using a stripped down version for testing and I left out some code lines that variables needed to be initialized. OK now.

    Thanks for your help


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width