Internal compiler error
Lee A Shombert
las@passaic.wash.inmet.com
Thu Sep 17 21:56:00 GMT 1998
I am reporting this 'bug' to you, as requested by the compiler. Note that I
have found perfectly adequate work-arounds. The source system is Redhat
5.1. The compiler version is:
----------------------------------------------------------------------------
$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
----------------------------------------------------------------------------
The compile command was:
----------------------------------------------------------------------------
g++ line.cc -o line
line.cc:64: Internal compiler error.
line.cc:64: Please submit a full bug report to `egcs-bugs@cygnus.com'.
----------------------------------------------------------------------------
The offending source is attached. Feel free to contact me if I can help.
Lee Shombert
/**
* File: line.cc
*
* Author:
**/
#include <iostream>
#include <string>
#include <math.h>
#include <stdio.h>
/**
* A point has just an x and y
**/
class Point {
public:
/**
* Construct a point from two coordinates
**/
Point(double xCoord = 0, double yCoord = 0) {
x = xCoord;
y = yCoord;
}
/**
* Return the midpoint
**/
Point midpoint(Point p) {
return Point((x - p.x) / 2 + p.x,
(y - p.y) / 2 + p.y);
}
/**
* Return the sum of two points
**/
Point operator+(const Point& a) {
return Point(x + a.x, y + a.y);
}
/**
* Return the point as a gnuplot string
**/
string toString() {
char temp[32];
sprintf(temp, "%lf %lf", x, y);
return string(temp);
}
/**
* Return the distance between two points
**/
double distance(const Point& p) {
return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y));
}
/**
* Return the angle formed by the point with respect to the x-axis, after
* translation to the the origin.
* @return the angle in radians
**/
double theta(const Point&origin = Point()) {
Point temp = Point(x - origin.x, y - origin.y);
return atan(temp.y / temp.x);
}
/**
* The coordinates
**/
double x;
double y;
/**
* Return a polar coordinate point. This cannot be a constructor becuase
* there is no way to distinguish it from the (x,y) constructor. The
* angle is in radians.
**/
static Point polar(double radius, double theta) {
return Point(radius * cos(theta), radius * sin(theta));
}
};
/**
*
**/
class Line {
public:
/**
* Construct a line from a slope and intercept. If the vertical flag is
* true, then the slope is interpreted as dx/dy, and not dy/dx.
**/
Line(double slope, double intercept, bool vertical = false) {
m = slope;
b = intercept;
byX = !vertical;
}
/**
* Construct a line from two points
**/
Line(Point p1, Point p2) {
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
if (dx != 0) {
m = dy / dx;
b = -m * p1.x + p1.y;
byX = true;
} else {
m = dx / dy;
b = -m * p1.y + p1.x;
byX = false;
}
}
/**
* Return the perpendicular through a point
**/
Line perpendicular(Point p) {
return Line(-1/m, 1/m * p.x + p.y);
}
/**
* Return the point for the given x coordinate
**/
Point forX(double x) {
return Point(x, m * x + b);
}
/**
* Return the point for the given y coordinate
**/
Point forY(double y) {
return Point((y-b)/m, y);
}
/**
* Return the intersecting point
**/
Point intersect(Line l) {
double nx = (l.b - b)/(m - l.m);
return Point( nx, m * nx + b);
}
/**
* The slope
**/
double m;
/**
* The intercept
**/
double b;
/**
* This flag indicates whether the line is by X or by Y. If true, then
* the line is by X, otherwise the line is by Y. We need the "by Y" case
* for vertical lines
**/
bool byX;
};
/**
* Plot a line for a range of x values
**/
static void plotLine(Line l) {
for (double x = -10; x <= 10; x += 0.2) {
cout << l.forX(x).toString() << endl;
}
cout << endl;
}
/**
* Show an arc that passes through three points
**/
static Point showArc(Point start, Point through, Point end) {
Line l1 = Line(start, end).perpendicular(start.midpoint(end));
Line l2 = Line(start, through).perpendicular(start.midpoint(through));
Point center = l1.intersect(l2);
return center;
}
extern int main(int argc, char **argv) {
double radius = 2.0;
Point offset = Point(4, 4);
Point a = Point::polar(radius, 0) + offset;
Point b = Point::polar(radius, .5) + offset;
Point c = Point::polar(radius, 1.2) + offset;
Point center = showArc(a, b, c);
cout << "# a: " << a.toString() << endl;
cout << "# b: " << b.toString() << endl;
cout << "# c: " << c.toString() << endl;
cout << "# : " << offset.toString() << endl;
cout << endl;
cout << "# " << center.toString() << endl;
cout << "# " << center.distance(a) << endl;
cout << "# " << center.distance(b) << endl;
cout << "# " << center.distance(c) << endl;
cout << endl;
cout << "# a@ " << a.theta(center) << endl;
cout << "# b@ " << b.theta(center) << endl;
cout << "# c@ " << c.theta(center) << endl;
return 0;
}
More information about the Gcc-bugs
mailing list