1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
int main(int argc, char *argv[])
{
long long int *IndexPtr;// index into a data structure
int *CoordPtr[4] // spacetime coordinates corresponding to this index
int s[4]; // used in the second example of code, unused here
int mu;
// Allocate memory for pointers
IndexPtr = new long long int;
*IndexPtr = {random integer from 0 to some max number}; // works fine
for (mu = 0; mu < 4; mu++)
{
CoordPtr[mu] = new int;
}
// map from an integer to 4D spacetime coordinates. input is *IndexPtr, output is CoordPtr
Index_to_Coord(*indexPtr, CoordPtr); // works fine, *CoordPtr contains the 4
// expected values
{do something, works fine}
// map from 4D spacetime coordinates to index
Coord_to_Index(IndexPtr, *CoordPtr); // IndexPtr is well defined here but only
// *CoordPtr[1] is correct
// in function Coord_to_Index; the others
//contain junk, so IndexPtr
// is meaningless but consistent
{do something more, then delete pointers}
return();
}
void Index_to_Coord(long long int Index2, int *Coord[4])
// returns spacetime Coordinates [t, x, y, z] given an index
{
*Coord[0...3] = {some integer function of Index2};
return;
}
// functions
void Coord_to_Index(long long int *Index1, int Coord2[4])
// returns index given 4D spacetime Coordinates
{
// Coord2 corrupted in function
*Index1 = {some long long integer function of Coord2}
return;
}
|