GCC Bug?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Please try out the following code snipet (not very large if you leave the 
commented lines away...

You can compile it with gcc -g 3d.c -lm -lvga -o 3d

If you try it out it produces a segmentation fault... (Why???)
If you declare the variable count a little bit further down it doesn't produce 
the segmentation fault. After I used ddd to locate the failure it told me 
that the variable count is overwritten with strange numbers that are out of 
the program memmory.

I'm using gcc 3.2.2 on slackware 9.0 

Isn't that strange ???

If you have any Idea what's going on there please let me know
I know you don't want to have code snipets but that was the only way to 
reproduce the error. So hope that helps....

Wolfgang Meyerle 

----_Snip-------------------------------------- 
#include <stdio.h>
#include <vga.h>
#include <math.h>

struct point3d
{
double x;
double y;
double z;
};

int main(void)
{
char a[1024];
int i;
int count;
char c;

struct point3d points[4];
struct point3d center;

points[0].x=-412;  
points[0].y=-50;
points[0].z=1;

points[1].x=+412;
points[1].y=-50;
points[1].z=1;

points[2].x=-412;
points[2].y=+50;
points[2].z=1;

points[3].x=+412;
points[3].y=+50;
points[3].z=1;

center.x=(1024)/2;
center.y=100+50;
center.z=0.5;

/*
      p[4]        p[5]
        v         v
        /---------/
p[0] > /_________/| p[1]
      |         | |
p[6] >| _______ | / p[7]
      |/---------/
p[2]  ^     p[3]^
*/
// ------------------------------------------
points[4].x=-412;
points[4].y=-50;
points[4].z=0.8;

points[5].x=+412;
points[5].y=-50;
points[5].z=0.8;

points[6].x=-412;
points[6].y=+50;
points[6].z=0.8;

points[7].x=+412;
points[7].y=+50;
points[7].z=0.8;

/*
if (vga_init()) return 1;
if (vga_setmode(G1024x768x256)) return(1);

vga_setcolor(200);
vga_setpalette(200,255,255,255);
*/
do
{
/*
vga_clear();


vga_drawline(center.x + 
points[0].x*points[0].z,center.y+points[0].y*points[0].z,center.x+points[1].x*points[1].z,center.y+points[1].y*points[1].z);
vga_drawline(center.x + 
points[0].x*points[0].z,center.y+points[0].y*points[0].z,center.x+points[2].x*points[2].z,center.y+points[2].y*points[2].z);

vga_drawline(center.x + 
points[1].x*points[1].z,center.y+points[1].y*points[1].z,center.x+points[3].x*points[3].z,center.y+points[3].y*points[3].z);
vga_drawline(center.x + 
points[2].x*points[1].z,center.y+points[2].y*points[2].z,center.x+points[3].x*points[3].z,center.y+points[3].y*points[3].z);

// ----------------------------------------------------------
vga_drawline(center.x + 
points[0].x*points[0].z,center.y+points[0].y*points[0].z,center.x+points[4].x*points[4].z,center.y+points[4].y*points[4].z);
vga_drawline(center.x + 
points[4].x*points[4].z,center.y+points[4].y*points[4].z,center.x+points[5].x*points[5].z,center.y+points[5].y*points[5].z);

vga_drawline(center.x + 
points[1].x*points[1].z,center.y+points[1].y*points[1].z,center.x+points[5].x*points[5].z,center.y+points[5].y*points[5].z);
vga_drawline(center.x + 
points[2].x*points[2].z,center.y+points[2].y*points[2].z,center.x+points[6].x*points[6].z,center.y+points[6].y*points[6].z);

vga_drawline(center.x + 
points[6].x*points[6].z,center.y+points[6].y*points[6].z,center.x+points[7].x*points[7].z,center.y+points[7].y*points[7].z);
vga_drawline(center.x + 
points[3].x*points[3].z,center.y+points[3].y*points[3].z,center.x+points[7].x*points[7].z,center.y+points[7].y*points[7].z);

vga_drawline(center.x + 
points[6].x*points[6].z,center.y+points[6].y*points[6].z,center.x+points[4].x*points[4].z,center.y+points[4].y*points[4].z);
vga_drawline(center.x + 
points[7].x*points[7].z,center.y+points[7].y*points[7].z,center.x+points[5].x*points[5].z,center.y+points[5].y*points[5].z);
*/

for (count=0;count<8;count++)
{
points[count].y=(points[count].y)*cos((double) (M_PI/180));
points[count].z=(points[count].z)*cos((double) (M_PI/180));
}

c=vga_getch();
} while (c!='a');

return 0;
}

--------------------------Snip-----------------

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux