delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/07/19/23:15:48

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Lines: 152
X-Admin: news AT aol DOT com
From: sterten AT aol DOT com (Sterten)
Newsgroups: comp.os.msdos.djgpp
Date: 20 Jul 2004 03:13:32 GMT
Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com
Subject: strange error
Message-ID: <20040719231332.11752.00001933@mb-m11.aol.com>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

X-No-archive: yes


with the program below I get this error :

---------------------------------------------------

C:\DJGPP>queensy4 16 2 3                                                       

Exiting due to signal SIGSEGV                                                  

General Protection Fault at eip=00001cdf                                       

eax=0000d270 ebx=a00f0706 ecx=00000099 edx=5ff0f90b esi=ffffff78 edi=ffffff78  

ebp=0009cca0 esp=0009cc50 program=C:\DJGPP\QUEENSY4.EXE                        

cs: sel=00a7  base=10000000  limit=0009ffff                                    

ds: sel=00af  base=10000000  limit=0009ffff                                    

es: sel=00af  base=10000000  limit=0009ffff                                    

fs: sel=008f  base=00019720  limit=0000ffff                                    

gs: sel=00bf  base=00000000  limit=0010ffff                                    

ss: sel=00af  base=10000000  limit=0009ffff                                    

App stack: [0009ccc0..0001ccc0]  Exceptn stack: [0001cc20..0001ace0]           

                                                                          
      
Call frame traceback EIPs:                                                     

  0x00001cdf _main+1631                                                        

  0x000037a8 ___crt1_startup+176                                               

                                                                          
      
C:\DJGPP>symify queensy4.exe                                                   

C:\DJGPP>scrsav >qser1                                                         

                                                                          
      
--------------------------------------------------

the program runs without errors, when I uncomment the
printf(""); - line above label m47:.
the program also runs correctly when compiled with the -g switch.
What's going on ? Why does the printf(""); change anything ?

--Guenter.

------------------------------------------------------------


// n even

int
s2[999],Sym[99][99],R[99]={0},C[99]={0},Di1[222]={0},Di2[222]={0},Col[99]={0};
int syms,x2,y2,r2,c2,Node[99],sy,u,v,x,y,q,w,n,r,i,solutions=0,c,p=0;
// C:column , Di1: diagonals SW-NE , Di2: diagonals NW-SE , Col:columns
// r:actual row , c:actual column

main(int argc,char*argv[]){
    if(argc<2){printf("usage:queen n x y\n\n 180'rotation-symmetric n-quees
solutions with\npreplaced queens on
(x,x),(y,n+1-y),(n+1-x,y),(n+1-y,n+1-x)\n");exit(1);}
    sscanf(argv[1],"%i",&n);if(n<0){n=-n;p=1;}

    for(x=1;x<=n;x++)for(y=1;y<=n;y++)Sym[x][y]=0;
    w=0;for(x=1;x<=n;x++)for(y=1;y<=n;y++){
     u=x;v=y;q=x*n+y;
     r=x*n+n+1-y;if(r<q){q=r;u=x;v=n+1-y;}
     r=(n+1-x)*n+n+1-y;if(r<q){q=r;u=n+1-x;v=n+1-y;}
     r=(n+1-x)*n+y;if(r<q){q=r;u=n+1-x;v=y;}
     r=y*n+x;if(r<q){q=r;u=y;v=x;}
     r=y*n+n+1-x;if(r<q){q=r;u=y;v=n+1-x;}
     r=(n+1-y)*n+n+1-x;if(r<q){q=r;u=n+1-y;v=n+1-x;}
     r=(n+1-y)*n+x;if(r<q){q=r;u=n+1-y;v=x;}
     if(Sym[u][v]==0){w++;Sym[u][v]=w;}
     Sym[x][y]=Sym[u][v];
    }syms=w;

//for(x=1;x<=n;x++){for(y=1;y<=n;y++)printf("%i
",Sym[x][y]);printf("\n");}printf("\n\n");

//goto m21;

    sscanf(argv[2],"%i",&x);x2=n+1-x;
    sscanf(argv[3],"%i",&y);y2=n+1-y;
    C[x]=x;R[x]=2;Col[x]=1;Di1[x+x]=1;Di2[x+n-x]=1;
    C[y]=y2;R[y]=2;Col[y2]=1;Di1[y+y2]=1;Di2[y+n-y2]=1;
    C[x2]=y;R[x2]=2;Col[y]=1;Di1[x2+y]=1;Di2[x2+n-y]=1;
    C[y2]=x2;R[y2]=2;Col[x2]=1;Di1[y2+x2]=1;Di2[y2+n-x2]=1;


m21:r=0;
m22:r++;if(R[r]  )goto m22;if(r>n)goto m50;
    C[r]=0;
m24:C[r]++;c=C[r];if(c>n)goto m55;
    r2=n+1-r;c2=n+1-c;if(r==c || r==c2)goto m24;
    if(Col[c])goto m24;
    if(Di1[r+c])goto m24;
    if(Di2[r+c2])goto m24;

    if(Col[c2])goto m24;
    if(Di1[r2+c2])goto m24;
    if(Di2[r2+c])goto m24;

    if(Col[r])goto m24;
    if(Di1[c+r2])goto m24;
    if(Di2[r+c])goto m24;

    if(Col[r2])goto m24;
    if(Di1[r+c2])goto m24;
    if(Di2[r2+c2])goto m24;

//for(i=1;i<=r;i++)printf("%i ",C[i]);printf("\n");
//printf("");

m47:Node[r]++;
    R[r]=1;R[r2]=2;R[c]=2;R[c2]=2;
    C[c]=r2;C[c2]=r;C[r2]=c2;C[r]=c;
    Col[c]=1;Col[c2]=1;Col[r]=1;Col[r2]=1;
    Di1[r+c]=1;Di1[r2+c2]=1;Di1[c+r2]=1;Di1[r2+c]=1;
    Di2[r+c2]=1;Di2[r2+c]=1;Di2[c+r]=1;Di2[c2+r2]=1;
    goto m22;
m50:solutions++; 
     for(x=0;x<=syms;x++)s2[x]=0;
     for(x=1;x<=n;x++)s2[Sym[x][C[x]]]=1;
     q=0;for(x=1;x<=syms;x++)q+=s2[x];
//    
if(q==n/2+1){for(x=1;x<=syms;x++)if(s2[x])printf("%c",64+x);printf("\n");}
 if(p){for(i=1;i<=n;i++)printf("%i ",C[i]);printf(" *\n");}
m55:r--;if(R[r]!=1)goto m55;
    c=C[r];r2=n+1-r;c2=n+1-c;
    R[r]=0;R[r2]=0;R[c]=0;R[c2]=0;
    C[c]=0;C[c2]=0;C[r2]=0;//C[r]=0;
    Col[c]=0;Col[c2]=0;Col[r]=0;Col[r2]=0;
    Di1[r+c]=0;Di1[r2+c2]=0;Di1[c+r2]=0;Di1[r2+c]=0;
    Di2[r+c2]=0;Di2[r2+c]=0;Di2[c+r]=0;Di2[c2+r2]=0;
    goto m57;

m57:if(r>0)goto m24;
    if(p==0)printf("%i solutions  \n",solutions);
//  for(i=1;i<=n;i++)printf("%i ",Node[i]);

}

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019