O3 versus O2 weirdness

barthek doli@ibt.com.pl
Mon Apr 16 12:11:00 GMT 2007


Hi there,

I have this small program here and am wondering why, when
compiled with O3 it does not produce any output at all ?
It works fine with O2.

Confirmed on gcc versions:
linux gcc version 3.4.6 (Gentoo Hardened 3.4.6-r2, ssp-3.4.6-1.0, 
pie-8.7.9)
linux gcc version 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)
openbsd gcc version 3.3.5 (propolice)

Not that I particularly need that or anything, but I can not really
find an explanation to this. Hope you know whats going on :)

Thanks,
B

The program is as follows:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int tab[13][20]={
   {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0},
   {0,0,0,0,0,1,0,0,0,0,0,1,1,1,0,0,0,1,0,0},
   {0,1,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,1},
   {1,0,0,1,0,0,0,1,0,1,0,0,0,1,1,0,0,1,0,0},
   {0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,1,0,0,1},
   {0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0},
   {1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,2,0},
   {0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,1,0,0,0,1},
   {0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,0,1,0,0,0},
   {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0}};

int tabx[13][20];
int sumy[20];

int licz(char *konfig)
{
  int i,n,l,el,ile=0;
  char c;

  memset(&sumy,0,sizeof(sumy));
  memset(&tabx,0,sizeof(tabx));

  for (i=0; i<=12; i++)
   for (n=0; n<=19; n++) {
    c=konfig[i];
    l=atoi(&c);
    el=l*tab[i][n];
    if (el>0) sumy[n]=sumy[n]+el;
    tabx[i][n]=el; }

  for (n=0; n<=19; n++)
     if (sumy[n]==3) ile++;
  return(ile);
}

int ile1(char *s)
{
  int i,n=0;
  for (i=0;i<=12;i++) if (s[i]=='1') n++;
  return(n);
}
void main()
{
  char komb[13];
  int a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad;
  int xx,w,ile;
for (xx=0;xx<=4;xx++)
  for (a1=0; a1<=1; a1++)
   for (a2=0; a2<=1; a2++)
    for (a3=0; a3<=1; a3++)
     for (a4=0; a4<=1; a4++)
      for (a5=0; a5<=1; a5++)
       for (a6=0; a6<=1; a6++)
        for (a7=0; a7<=1; a7++)
         for (a8=0; a8<=1; a8++)
          for (a9=0; a9<=1; a9++)
           for (aa=0; aa<=1; aa++)
            for (ab=0; ab<=1; ab++)
             for (ac=0; ac<=1; ac++)
              for (ad=0; ad<=1; ad++)
               {

 		sprintf(komb,"%d%d%d%d%d%d%d%d%d%d%d%d%d",a1,a2,a3,a4,a5,a6,a7,a8,a9,aa,ab,ac,ad);
                w=licz(komb);
                ile=ile1(komb);
                if ((w==1) && (ile<=3))
                 {
                 printf("%s\t%d\t%d\n",komb,w,ile);
                 }
               }
}



More information about the Gcc-help mailing list