On Tue, 29 Jun 2004 09:07:28 -0300
Davi de Castro Reis
Maybe gcc is a bit "smarter" (?) with the initializations...
I don't think so. You probably has a problem in the Vertex3d copy constructor.
I think I agree with Davi here, but another comment on automatic and
allocated variables :
Automatic and malloc'd variables are not initialized. it is very
possible that in the Linux environment, the garbage you picked up might
have been benign where under VC, the garbage might have been bad.
Example:
#include <iostream>
using std::cout;
int main()
{
double x;
cout << x << '\n';
}
In the above case, x could contain anything from 0.0 through any valid
value, and possibly some invalid value, and cause a floating point
exception. It depends solely on what the C run time library does before
main is called. Same with Visual C. Class variables are likewise not
initialized unless you explicitly do so in a constructor.
One issue that Davi picked up was your coding style.
Cone cone1(*(new Vertex3d(10*x, 0, 10*z, 100)), 1, *(new
Vertex3d(10*x, 0, 10*z+5, 2)),0.00);
In addition to the memory leak issue, you are making the code hard to
read. One of the oldest rules I try to use is to maintain the
readability of my code. Maybe it comes from writing an old program in
PDP-8 assembler, putting it down for finals, and after finals, picking
it up and finding it was impossible for me to read.
Additionally, your expressions, such as 10 * x are going to be evaluated
at run time unless the compiler can optimize them. It might be better:
const float x=2.0, y=6.0f, z=1.5; // Now these are constants
and therefore, 10 * x is a constant expression evaluated at compile
time. Some programmers might also prefer to use 10.0 * x, but todays
compilers will generate the right code.
--
Jerry Feldman