Mail Archives: djgpp/1999/10/04/19:28:27
From: | sunegn AT image DOT dk (Sune Nielsen)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Newbie: HELP! It won't work!!!!
|
Message-ID: | <37f92508.181091@news.image.dk>
|
X-Newsreader: | Forte Agent 1.5/32.451
|
MIME-Version: | 1.0
|
Lines: | 202
|
Date: | Mon, 04 Oct 1999 22:22:05 GMT
|
NNTP-Posting-Host: | 212.54.68.104
|
X-Complaints-To: | news-abuse AT wol DOT dk
|
X-Trace: | news010.image.dk 939068660 212.54.68.104 (Mon, 04 Oct 1999 22:24:20 MET DST)
|
NNTP-Posting-Date: | Mon, 04 Oct 1999 22:24:20 MET DST
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Please don't rip my head off for posting this rather longish email,
but I seriously need help :(
I've recently upgraded DJGPP from version 2.01 to 2.02, and now, for
some reason of which I have absolutely no idea, it compiles my code
into completely rubbish. Well... it actually compiles rather fine, but
when I try to run the program it tells me something like
<snip>----------------------
Call frame traceback:
in function malloc+99
in function _flsbuf+76
etc...
<snip>---------------------
I mean "malloc"... I don´t even use that function (it´s supposed to be
C++ ;)
Have I totally missed some point or... is my code really that buggy? I
am positive that it worked under v2.01!
Please help me & thanks in advance...
Yours sincerly,
Sune G. Nielsen
sunegn AT image DOT dk
<buggy code starts here...>
#include <iostream.h>
class object_3d{
private:
struct vertex {double x,y,z,w;};
struct facet { facet *nextfacet;
vertex vertex_array[2];
};
facet* first_facet;
facet* last_facet;
int numoffacets;
public:
object_3d(void);
~object_3d(void);
facet* new_facet(void);
void add_facet(facet *f);
void delete_facet(facet *f);
void print_all(void);
};
object_3d::object_3d()
{
first_facet=NULL;
last_facet=NULL;
numoffacets=NULL;
}
object_3d::~object_3d()
{
facet* f=first_facet; //get_first_facet();
facet* temp;
while (f!=NULL)
{
temp=f->nextfacet;
delete_facet(f);
f=temp;
}
}
object_3d::facet* object_3d::new_facet(void)
{
facet* pointer= new facet;
pointer->nextfacet=NULL;
return (pointer);
}
void object_3d::add_facet(facet *f)
{
facet* nf=first_facet; //lav pointer til nfacet
facet* temp;
if (nf==NULL) {first_facet=f;}
else
{
while (nf->nextfacet!=NULL) //s†l‘nge nf->next<> 0 g† ned i
r‘kken
{
nf=nf->nextfacet;
} //indtil = 0 (den sidste)
nf->nextfacet=f; //l‘g ny facet bagerst i r‘kken
f->nextfacet=NULL; //ikke flere facets
last_facet=f;
}
numoffacets+=1;
}
void object_3d::delete_facet(facet *f)
{
if (first_facet!=NULL)
{
facet* temp=first_facet;
if (first_facet==f)
{
first_facet=first_facet->nextfacet;
delete f;
}
else
{
while (temp->nextfacet!=f)
{
temp=temp->nextfacet;
}
temp->nextfacet=f->nextfacet;
}
delete f;
numoffacets-=1;
temp=first_facet;
while (temp!=NULL)
{
last_facet=temp;
temp=temp->nextfacet;
}
}
else cout << "ERROR: No facets to delete" << endl << "Reason:
Selected facet has not been merged into object" << endl;
}
void object_3d::print_all(void)
{
facet *fp;
fp=first_facet;
if (fp==NULL)
{
cout << "object contains NO facets!" << endl;
}
else
{
int num=1;
while (fp!=NULL)
{
cout << "facet no. " << num << endl;
for (int vert=0;vert<3;vert++)
{
cout << "vertex no. " << vert << " : (" <<
fp->vertex_array[vert].x << "," << fp->vertex_array[vert].y << "," <<
fp->vertex_array[vert].z << ")" << endl;
}
cout << endl;
fp=fp->nextfacet;
num+=1;
}
cout << "No. of facets: " << numoffacets << endl << endl;
}
}
void main(void)
{
object_3d cube;
object_3d::facet *one;
one=cube.new_facet();
one->vertex_array[0].x=1.10;
one->vertex_array[0].y=1.10;
one->vertex_array[0].z=1.10;
one->vertex_array[0].w=1.10;
one->vertex_array[1].x=1.20;
one->vertex_array[1].y=1.20;
one->vertex_array[1].z=1.20;
one->vertex_array[1].w=1.20;
one->vertex_array[2].x=1.20;
one->vertex_array[2].y=1.20;
one->vertex_array[2].z=1.20;
one->vertex_array[2].w=1.20;
cube.add_facet(one);
cube.print_all();
cube.delete_facet(one);
cube.print_all();
}
- Raw text -