www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/26/09:00:39

From: Thomas Demmer <demmer AT LSTM DOT Ruhr-UNI-Bochum DOT De>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: I'm going slightly mad!!
Date: Thu, 26 Feb 1998 10:46:09 +0100
Organization: Lehrstuhl fuer Stroemungsmechanik
Lines: 48
Message-ID: <34F539E1.3347E282@LSTM.Ruhr-UNI-Bochum.De>
References: <Pine DOT OSF DOT 3 DOT 91 DOT 980224095752 DOT 136A-100000 AT leofric> <34F50789 DOT 3AB6 AT stud DOT warande DOT ruu DOT nl>
NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019