Mail Archives: djgpp/1998/02/26/09:00:39
Elliott Oti wrote:
>
> My guess would be you're writing to invalid pointers somewhere.
>
> I have made some dumb mistakes in my time, and I hope you will forgive
> the liberty of
> sharing one with you. Who knows, it may help. I call it:
>
> "Reading integer offsets from files and forgetting that arrays in C
> begin from 0."
>
> and it goes like this:
>
> I read an array of N points from a 3d object file.
> Then I read a triangle in. It is composed of points 15, 16, and 17 of my
> array.
> At least, that's what the file says. So I say:
> triangle T = { Array[15], Array[16], Array[17] }
[... rest of very familiar bug removed]
Two solutions:
1.) Start numbering your points with 0, that's what I do in
my FEM/FVM code when working on unstructured grids.
2.) Do something like
Array = malloc(n*sizeof(*Array));
--Array;
...
free(++Array);
Then you have Array[1]..Arrray[n] as valid subscripts.
Whatever you do, do it consistently.
--
Ciao
Tom
*************************************************************
* Thomas Demmer *
* Lehrstuhl fuer Stroemungsmechanik *
* Ruhr-Uni-Bochum *
* Universitaetsstr. 150 *
* D-44780 Bochum *
* Tel: +49 234 700 6434 *
* Fax: +49 234 709 4162 *
* http://www.lstm.ruhr-uni-bochum.de/~demmer *
*************************************************************
- Raw text -